x***@126.com
x***@126.com
  • 发布:2022-11-02 21:56
  • 更新:2023-08-24 19:12
  • 阅读:246

speech.addEventListener问题

分类:HTML5+

speech.addEventListener问题

环境vue3,页面监听事件后,关闭页面没有移除事件,再次打开会继续新增事件监听,依次多次打开监听事件不断叠加,导致事件信息找不到,建议增加一个移除事件的方法。

<script setup>  
    import { onMounted, onUnmounted, reactive, ref } from "vue";  
    const info = reactive({  
        title: '',  
        text: '',  
        result: '',  
        volume: '0px',  
        partial: ''  
    })  
    const emits = defineEmits(['success']);  

    onMounted(() => {  
        // #ifdef APP-PLUS  
        plus.speech.addEventListener('start', onSpeechStart, false);  
        plus.speech.addEventListener('volumeChange', onVolumeChange, false);  
        plus.speech.addEventListener('recognizing', onRecognizing, false);  
        plus.speech.addEventListener('recognition', onRecognition, false);  
        plus.speech.addEventListener('end', onSpeechEnd, false);  
        // #endif  
    })  

    function onSpeechStart() {  
        info.title = '倾听中...';  
        info.text = '';  
        console.log(info.result);  
    }  

    function onVolumeChange(e) {  
        info.volume = 200 * e.volume + 'px';  
    }  

    function onRecognizing(e) {  
        info.partial = e.partialResult;  
    }  

    function onRecognition(e) {  
        info.partial = e.result;  
        if (e.result) {  
            info.text += e.result;  
            info.result = info.text;  
        }  
    }  

    function onSpeechEnd() {  
        info.result = info.text;  
        info.title = '未开始';  
        info.volume = '0px';  
        info.partial = ''  
    }  

    function startRecognize() {  
        plus.speech.startRecognize({ engine: 'baidu', lang: 'zh-cn', 'userInterface': false, 'continue': true });  
    }  

    function endRecognize() {  
        plus.speech.stopRecognize();  
    }  

    function submitHandle() {  
        emits('success', info.result || '');  
    }  
</script>
2022-11-02 21:56 负责人:无 分享
已邀请:
Mkit

Mkit - 那就这样吧

这个问题官方还没有回复吗

5***@qq.com

5***@qq.com

请问,您的 recognition 能正常执行吗,我的 recognizing 能得到转化的文字,recognition 一直没走

  • 浅笑

    我也是

    2023-10-11 16:05

要回复问题请先登录注册