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
网友回复
如何破解绕开seedance2.0真人照片生成视频 限制?
python有哪些算法可以将视频中的每个帧图片去除指定区域水印合成新的视频?
iphone的激光雷达数据能否实时传输到three三维空间中?
豆包sora等ai视频生成大模型生成的视频水印如何去除?
python如何实现在电脑上拨号打电话给手机?
具身机器人与人形机器人区别?
nodejs如何将一个完整的js代码文件切割成不同的部分混淆后动态加载进入html运行?
为啥windows.onerror捕获js错误是这样的{"message":"Script error.","source":"","lineno":0,"colno":0,"stack":null,
2026年ai将全面接管编程?
WebMCP是干啥的?


