更新记录
1.0.0(2025-08-17) 下载此版本
yao-asdRealtimeSpeech
阿里云Paraformer实时语音识别
平台兼容性
uni-app(4.07)
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | × | × | √ | × | √ | √ | × |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × | × | × |
yao-asdRealtimeSpeech
配置
需要将模块下uni_modules/yao-RecordFrame的dist复制到static目录下面 或者 将uni_modules/yao-RecordFrame/dist目录的配置文件放到static/dist目录下面
代码示例
<template>
<view class="content">
<view class="btn-start" @click="onStart">开始说话</view>
<view class="btn-stop" @click="onStop">停止说话</view>
<view style="width:90%;margin:0 auto;;">
{{text}}
</view>
<yao-asdRealtimeSpeech
ref="asdTimeSpeeh"
:options="asdOptions"
@result="onResult"
@change="onChange"
></yao-asdRealtimeSpeech>
</view>
</template>
<script>
export default {
data() {
return {
text:"",
asdOptions:{
apikey:"", //自己申请的密钥
language_hints:["zh","ja"], //识别语言代码 如果无法提前确定语种,可不设置 (当前设置了中文+日语)
},
}
},
onLoad() {
},
methods: {
onStart(){
//开始识别
console.log('开始识别');
this.$refs.asdTimeSpeeh.start();
this.text="";
},
onStop(){
//停止识别
console.log('停止识别');
this.$refs.asdTimeSpeeh.stop();
},
onResult(res){
//识别结果
console.log(res);
this.text = res.sentence.text;
},
onChange(msg){
console.log(msg)
if(msg.status == "CLOSE"){
//连接已关闭
}else if(msg.status == "START"){
//开始录音
}else if(msg.status == "ERROR"){
//连接发生错误
}
}
}
}
</script>