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如何实现torrent的服务端进行文件分发p2p下载?
如何在浏览器中录制摄像头和麦克风数据为mp4视频保存下载本地?
go如何编写一个类似docker的linux的虚拟容器?
python如何写一个bittorrent的种子下载客户端?
ai能通过看一个网页的交互过程视频自主模仿复制网页编写代码吗?
ai先写功能代码通过chrome mcp来进行测试功能最后ai美化页面这个流程能行吗?
vue在手机端上下拖拽元素的时候如何禁止父元素及body的滚动导致无法拖拽完成?
使用tailwindcss如何去掉响应式自适应?
有没有直接在浏览器中运行的离线linux系统?
nginx如何保留post或get数据进行url重定向?