首先先配置好权限
注意:iFLYTEK语音识别和百度语音识别不能同时支持。你只能在两个中选择一个。
[En]
Note: iFLYTEK speech recognition and Baidu speech recognition are not supported at the same time. You can only choose one of the two.
百度语音识别
在manifest.json文件”App模块配置”项的”Speech(语音输入,只能选一个)”下,勾选”百度语音识别”项,并输入从百度开放平台申请的参数:
- appid:
百度语音开放平台申请的AppID - apikey:
百度语音开放平台申请的API Key - secretkey:
百度语音开放平台申请的Secret Key
请到百度语音开放平台申请:https://console.bce.baidu.com/ai/
讯飞语音识别
在manifest.json文件”App模块配置”项的”Speech(语音输入,只能选一个)”下,勾选”讯飞语音识别”项:
注:iFLYTEK语音识别有识别次数限制,建议优先使用百度语音识别。
[En]
Note: iFLYTEK speech recognition has a limit on the number of recognition times, it is recommended to give priority to using Baidu speech recognition.
配置完成后Ctrl+S保存提交App云端打包生效。
不管你用哪一个,记住,都是有次数限制的,讯飞,uniapp官网支持,所以并不需要配置什么,但是你最好还是自己上讯飞官网申请创建一个语音识别应用,不然到时候你云打包的时候,真的不知道他在读什么鸟语,我猜测是次数用完限制了,不啰嗦,上代码
var receiver = plus.android.implements('com.iflytek.cloud.SynthesizerListener', {
onEvent: function(name) {
console.log("onEvent");
},
onSpeakBegin: function() {
console.log("开始阅读");
},
onSpeakPaused: function() {
console.log(" 暂停播放 ");
},
onSpeakResumed: function() {
console.log("继续播放");
},
onBufferProgress: function(percent, beginPos, endPos, info) {
console.log("合成进度" + percent);
},
onSpeakProgress: function(percent, beginPos, endPos) {
console.log("播放进度" + percent);
},
onCompleted: function(error) {
console.log("播放完毕");
}
});
var main = plus.android.runtimeMainActivity();
var SpeechUtility = plus.android.importClass('com.iflytek.cloud.SpeechUtility');
//这里的appid填你自己申请的
SpeechUtility.createUtility(main, "appid=xxxxx");
var SynthesizerPlayer = plus.android.importClass('com.iflytek.cloud.SpeechSynthesizer');
var play = SynthesizerPlayer.createSynthesizer(main, null);
// 开始合成
play.startSpeaking('生活就是海洋', receiver);
注意:如果要在本地测试,必须使用自定义库,否则将无效。
[En]
Note: if you want to test locally, you must use a custom base, otherwise it will be invalid.
如果你感兴趣,可以关注公众号,不定期分享一些事情。也欢迎您的贡献和分享!谢谢
[En]
If you are interested, you can follow the official account and share some things irregularly. You are also welcome to contribute and share! Thank you
Original: https://blog.csdn.net/qq_37049128/article/details/108468717
Author: 菜鸟咸鱼一锅端
Title: uniapp-语音识别
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/526595/
转载文章受原作者版权保护。转载请注明原作者出处!