1、使用插件,小程序后台设置-第三方服务-插件管理中搜索微信同声传译或腾讯云智能语音,使用这个插件即可实现实时语音识别。
微信同声传译不仅能实时识别,还是实时翻译成指定国家的语音,支持文本转语音合成,关键还是免费的
const plugin = requirePlugin('WechatSI'); const manager = plugin.getRecordRecognitionManager() manager.onStop = function(res) { console.log("record file path", res.tempFilePath) console.log("result", res.result) } manager.onStart = function(res) { console.log("成功开始录音识别", res) } manager.onError = function(res) { console.error("error msg", res.msg) } plugin.textToSpeech({ lang: "zh_CN", tts: true, content: "一个常见的需求", success: function(res) { //这个res.filename是生成后的声音文件地址url, console.log("succ tts", res.filename) }, fail: function(res) { console.log("fail tts", res) } }) manager.start({ duration: 3000, lang: "zh_CN" }) manager.stop() plugin.translate({ lfrom:"en_US", lto:"zh_CN", content:"hello, this is the first time to test?", success: function(res) { if(res.retcode == 0) { console.log("result", res.result) } else { console.warn("翻译失败", res) } }, fail: function(res) { console.log("网络失败",res) } })文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/translator.html
腾讯云智能语音不仅能使用语音,还能合成语音,但是需要开通腾讯云服务,收费的:文档:https://cloud.tencent.com/document/product/1093/48982
2、使用第三方,例如百度、阿里云的实时语音识别api,通常是websocket的形式
阿里的paraformer实时识别引擎,能实时识别中文和其他方言,也非常便宜,开发文档:
https://help.aliyun.com/zh/model-studio/developer-reference/paraformer-real-time-speech-recognition-api
python示例代码
https://github.com/aliyun/alibabacloud-bailian-speech-demo/blob/master/samples/speech-recognition/recognize_speech_from_microphone/python/run.py
网友回复
python如何调用openai的api实现知识讲解类动画讲解视频的合成?
html如何直接调用openai的api实现海报可视化设计及文本描述生成可编辑海报?
f12前端调试如何找出按钮点击事件触发的那段代码进行调试?
abcjs如何将曲谱播放后导出mid和wav格式音频下载?
python如何将曲子文本生成音乐mp3或wav、mid文件
python中mp3、wav音乐如何转成mid格式?
js在HTML中如何将曲谱生成音乐在线播放并下载本地?
python如何实现在windows上通过键盘来模拟鼠标操作?
python如何给win10电脑增加文件或文件夹右键自定义菜单?
python如何将音乐mp3文件解析获取曲调数据?