微信小程序中确实存在一个免费的同声传译语音转文字插件,名为“微信同声传译”。这个插件由微信自研,提供了语音输入、文本翻译和语音合成等功能,允许第三方小程序调用。
以下是使用该插件的基本步骤:
安装插件:在微信小程序管理后台的“插件管理”中搜索“同声传译”插件并进行安装。
配置小程序:在小程序的app.json文件中配置插件信息,如下所示:
//app.json { ... "plugins": { ... "WechatSI": { "version": "0.3.1", "provider": "wx069ba97219f66d99" } } }
使用插件功能:在小程序页面的JavaScript文件中,引入插件并使用其提供的功能。例如,使用语音识别功能:
//index.js var plugin = requirePlugin("WechatSI") let manager = plugin.getRecordRecognitionManager() manager.onRecognize = function(res) { console.log("current result", res.result) } 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) } manager.start({duration:30000, lang: "zh_CN"})
实现语音转文字:通过recordRecoManager对象的方法,如start、stop、onStart、onStop和onError等,来实现语音转文字的功能。
文本翻译和语音合成:插件还支持文本翻译和语音合成功能,可以通过相应的接口进行调用。
该插件支持的语言包括中文(中国大陆)、英文等,并且提供了实时流式识别能力。开发者可以利用这个插件轻松实现语音读取识别、文本转语音和中英文文本转换等功能,避免重复开发工作。
此外,微信同声传译插件还提供了详细的开发文档和使用案例,开发者可以在微信开放文档中找到更多信息和示例代码。
插件地址:https://mp.weixin.qq.com/wxopen/plugindevdoc?appid=wx069ba97219f66d99&token=61191740&lang=zh_CN
还支持文本翻译
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) } })tts语音合成
plugin.textToSpeech({ lang: "zh_CN", tts: true, content: "一个常见的需求", success: function(res) { console.log("succ tts", res.filename) }, fail: function(res) { console.log("fail tts", res) } })
网友回复