1. 首先我們先在開(kāi)發(fā)者工具給他添加第三方插件
然后我們?cè)?小程序的manifest.json切換成源碼視圖 然后在appid同級(jí)目錄添加插件 其中provider是第三方插件的appid
然后在你要進(jìn)行翻譯的文件里面引入
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-610753.html
<template>
<view>
<view class="voicepad">
{{voiceState}}
</view>
<button class="cu-btn bg-green voicebtn " @touchstart="touchStart" @touchend="touchEnd">
<image src="../../static/yuyue/maikef.png" mode="widthFix" style="width: 50rpx;"></image>
</button>
<view class="center" style="background-color: #555555; color: #FFF;" v-show="isShow">
正在錄音...
</view>
</view>
</template>
<script>
var plugin = requirePlugin("WechatSI")
let manager = plugin.getRecordRecognitionManager();
export default {
data() {
return {
voiceState: "你可以這樣說(shuō)...",
isShow: false
}
},
onShow() {
},
onLoad() {
this.initRecord();
},
methods: {
touchStart: function() {
// uni.showToast({
// title: '正在錄音',
// icon: "none"
// })
this.isShow = true
manager.start({
duration: 60000,
lang: "zh_CN"
});
},
touchEnd: function() {
// uni.showToast({
// title: '錄音完成',
// icon: "none"
// })
this.isShow = false
manager.stop();
},
/**
* 初始化語(yǔ)音識(shí)別回調(diào)
* 綁定語(yǔ)音播放開(kāi)始事件
*/
initRecord: function() {
manager.onStart = function(res) {
console.log('start',res.msg);
this.voiceState = res.msg;
};
//有新的識(shí)別內(nèi)容返回,則會(huì)調(diào)用此事件
manager.onRecognize = (res) => {
this.voiceState = res.result;
console.log('onRecognize');
}
// 識(shí)別結(jié)束事件
manager.onStop = (res) => {
this.voiceState = res.result;
console.log('onStop',res.result);
}
// 識(shí)別錯(cuò)誤事件
manager.onError = (res) => {
this.voiceState = res.msg;
console.log('onError');
}
},
}
}
</script>
<style>
.voicebtn {
height: 130upx;
display: block;
width: 130upx;
line-height: 130upx;
border-radius: 65upx;
font-size: 50upx;
position: absolute;
top: 1060upx;
left: 310upx;
}
.voicepad {
height: 250upx;
width: 680upx;
background: #fff;
margin: 30upx auto;
border-radius: 8upx;
padding: 20upx;
font-size: 35upx;
}
.center {
text-align: center;
align-items: center;
width: 200rpx;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20rpx;
border-radius: 20rpx;
/* height: 50rpx; */
opacity: 0.8;
}
</style>
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-610753.html
到了這里,關(guān)于關(guān)于小程序uniapp同聲傳譯(語(yǔ)音轉(zhuǎn)文字)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!