3***@qq.com
3***@qq.com
  • 发布:2023-07-24 12:08
  • 更新:2023-10-11 16:07
  • 阅读:228

hbuilderx语音识别一直显示无法识别到内容

分类:uni-app

<!-- <template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
</view>
</template>

<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {

    },  
    methods: {  

    }  
}  

</script>

<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.logo {  
    height: 200rpx;  
    width: 200rpx;  
    margin-top: 200rpx;  
    margin-left: auto;  
    margin-right: auto;  
    margin-bottom: 50rpx;  
}  

.text-area {  
    display: flex;  
    justify-content: center;  
}  

.title {  
    font-size: 36rpx;  
    color: #8f8f94;  
}  

</style>
-->

<template>
<view class="content">
<textarea class="result" placeholder="语音识别内容" :value="result"></textarea>
<view class="recogniz">
<view style="color: #0000CC;">
<text>{{title}}</text>
</view>
<view class="partial">
<text>{{partialResult}}</text>
</view>
<view class="volume" :style="{width:valueWidth}"></view>
</view>
<button type="default" @touchstart="startRecognize" @touchend="endRecognize">按下开始&松开结束</button>
</view>
</template>
<script>
export default {
data() {
return {
title: '未开始',
text: '',
partialResult: '...',
result: '',
valueWidth: '0px'
}
},
onLoad() {
// #ifdef APP-PLUS
// 监听语音识别事件
plus.speech.addEventListener('start', this.ontStart, false);
plus.speech.addEventListener('volumeChange', this.onVolumeChange, false);
plus.speech.addEventListener('recognizing', this.onRecognizing, false);
plus.speech.addEventListener('recognition', this.onRecognition, false);
plus.speech.addEventListener('end', this.onEnd, false);
// #endif
},
methods: {
ontStart() {
this.title = '...倾听中...';
this.text = '';
console.log('Event: start');
},
onVolumeChange(e) {
console.log("正在倾听中。。。。。")
this.valueWidth = 100*e.volume+'px';
console.log('Event: volumeChange: '+this.valueWidth);
},
onRecognizing(e) {
console.log("onRecognizing........");
this.partialResult = e.partialResult;
console.log('Event: recognizing');
},
onRecognition(e) {
this.text += e.result;
this.text?(this.text+='\n'):this.text='';
this.result = this.text;
this.partialResult = e.result;
console.log('Event: recognition=======');
},
onEnd() {
if(!this.text||this.text==''){
plus.nativeUI.toast('没有识别到内容');
}
this.result = this.text;
this.title = '未开始';
this.valueWidth = '0px';
this.partialResult = '...';
console.log("ending。。。。。。。")
},
startRecognize() {
// #ifdef APP-PLUS
console.log('startRecognize。。。。。。');
plus.speech.startRecognize({
engine: 'baidu',
lang: 'zh-cn',
'userInterface': false,
'continue': true
},function(e){
console.log("语音识别失败.。。。。。。。")
});
// #endif
},
endRecognize() {
console.log('endRecognize。。。。。。');
// #ifdef APP-PLUS
plus.speech.stopRecognize();
// #endif
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.recogniz {
width: 200px;
height: 100px;
padding: 12px;
margin: 50px auto;
background-color: rgba(0,0,0,0.5);
border-radius: 16px;
text-align: center;
}
.partial {
width: 100%;
height: 40px;
margin-top: 16px;
font-size: 12px;
color: #FFFFFF;
}
.volume {
width: 10px;
height: 6px;
border-style:solid;
display:inline-block;
box-sizing:border-box;
border-width:1px;
border-color:#CCCCCC;
border-radius: 50%;
background-color: #00CC00;
}
.result {
color: #CCCCCC;
border: #00CCCC 1px solid;
margin: 25px auto;
padding: 6px;
width: 80%;
height: 100px;
}
</style>

2023-07-24 12:08 负责人:无 分享
已邀请:
浅笑

浅笑

userInterface不能设置为false。烦得很。文档里面也不说

  • Hcode

    谢谢大佬

    2024-03-13 14:48

  • 3***@qq.com

    不行呀,我改了,一样不可以

    2024-04-12 11:11

  • 3***@qq.com

    回复 Hcode: 你解决了嘛?

    2024-04-12 11:11

  • House1

    回复 Hcode: 解决了吗

    2024-04-12 11:30

要回复问题请先登录注册