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
网友回复
deepseek v4与glm5.1 kim2.6 qwen3.6哪个ai模型更强更好用?
gpt-image2能直接将图片转成分层透明的psd设计文件?
claude code、codex、gemini cli如何切换国内大模型使用?
蒸馏最强ai大模型是中小ai模型低成本升级的最好通道?
arena.ai上为啥没有最新的claude4.7及gpt5.5呢?
ai大模型公司为啥开始大量招聘文科生了?
cloudflared如何在低版本centos6或7上安装?
bfwsoa框架如何开启异步缓存与异步任务模式?
selenium如何获取网页js加载渲染后的真实dom结构?
go编写的Eino与python编写的langchain如何选择?


