第一步:現(xiàn)在微信小程序管理后臺(tái):“設(shè)置”-》“第三方設(shè)置”-》“插件管理”中添加插件。
但是這個(gè)地方,沒有搜索到插件,就到微信服務(wù)市場(chǎng)去搜微信服務(wù)市場(chǎng)
?搜索到以后添加到需要的小程序里面,然后返回管理中心查看,就可以看到了
第二步:在配置文件中引入插件
第三步:在需要使用的頁面引入:
var plugin = requirePlugin("WechatSI")
let manager = plugin.getRecordRecognitionManager()?
頁面代碼:
<button @touchstart="streamRecord" @touchend="endStreamRecord" form-type="submit" type="primary" class="fc-white">語音識(shí)別按鈕</button>
?? ??? ??? ?<view> 語音識(shí)別內(nèi)容:{{currentText}} </view>
js代碼:
data中定義:data() {
?? ??? ??? ?return {
?? ??? ??? ??? ?currentText:""
?? ??? ??? ?}
?? ??? ?},
在methods中定義方法:
streamRecord: function(){
?? ??? ??? ??? ?console.log('=======開始====')
?? ??? ??? ? ? manager.start({
?? ??? ??? ? ? ? lang: 'zh_CN',
?? ??? ??? ? ? })
?? ??? ??? ?},
?? ??? ??? ?endStreamRecord: function(){
?? ??? ??? ??? ?console.log('=======結(jié)束====')
?? ??? ??? ??? ?manager.stop()
?? ??? ??? ?},
?? ??? ??? ?initRecord: function(){
?? ??? ??? ????//有新的識(shí)別內(nèi)容返回,則會(huì)調(diào)用此事件
?? ??? ??? ????manager.onRecognize = (res) => {
?? ??? ??? ??????let text = res.result
?? ??? ??? ??????this.currentText = text
?? ??? ??? ????}
?? ??? ??? ????// 識(shí)別結(jié)束事件
?? ??? ??? ????manager.onStop = (res) => {
?? ??? ??? ??????let text = res.result
?? ??? ??? ??????if(text == '') {
?? ??? ??? ??? ??? ?console.log('沒有說話')
?? ??? ??? ???????return
?? ??? ??? ??????}
?? ??? ??? ??????this.currentText = text
?? ??? ??? ????}
?? ??? ??? ?},
在onLoad中調(diào)用初始化:
onLoad() {
?? ??? ??? ?this.initRecord()
?? ??? ?},文章來源:http://www.zghlxwxcb.cn/news/detail-489258.html
然后就可以正常使用了。文章來源地址http://www.zghlxwxcb.cn/news/detail-489258.html
到了這里,關(guān)于uniapp開發(fā)微信小程序,使用微信同聲傳譯插件,實(shí)現(xiàn)語音識(shí)別輸入文本的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!