Skip to content

Commit 1ec3f39

Browse files
committed
bugfix on the speech recognition func
1 parent 4ff4fc0 commit 1ec3f39

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

widget/components/chat/PromptControls.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<template>
22
<div v-if="store.speechRecognition && (!store.promptWithText || store.speechRecognitionTranscribing)" :class="{'dark-mode': store.darkMode}" class="prompt-right-button"
33
@click="() => {
4-
if (activeMicro)
5-
if (sttPhrase && sttPhrase.started){
4+
if (activeMicro) {
5+
if (sttPhrase && sttPhrase.started) {
66
speechRecognitionPhraseActivated = true
77
sttPhrase.stop()
8+
} else {
9+
stt.value.start();
810
}
9-
stt.start()
11+
}
1012
}">
1113
<div v-if="store.speechRecognitionTranscribing" class="micro-anim-elm has-scale-animation"></div>
1214
<div v-if="store.speechRecognitionTranscribing" class="micro-anim-elm has-scale-animation has-delay-short"></div>
@@ -75,10 +77,13 @@ function _initSTT(continuous = false) {
7577
sr.continuous = continuous;
7678
sr.interimResults = true;
7779
sr.maxAlternatives = 1;
80+
sr.started = false;
7881
7982
sr.addEventListener("audioend", sr.stop)
8083
sr.addEventListener("soundend", sr.stop)
8184
sr.addEventListener("speechend", sr.stop)
85+
sr.addEventListener("start", () => sr.started = true)
86+
sr.addEventListener("end", () => sr.started = false)
8287
8388
sr.onerror = (event) => {
8489
console.log('Error occurred in the speech recognition:', event)
@@ -123,7 +128,7 @@ function initSTT() {
123128
if (window.speechDebug)
124129
console.log(`%c ${text} `, "color: #00FF00");
125130
}
126-
stt.value.onend = () => {
131+
stt.value.addEventListener("end", () => {
127132
store.speechRecognitionTranscribing = false;
128133
129134
if (store.speechRecognitionBeep)
@@ -134,7 +139,7 @@ function initSTT() {
134139
135140
if (store.speechRecognitionPhraseActivation)
136141
sttPhrase.value.start();
137-
}
142+
})
138143
}
139144
140145
function initSTTPhrase() {
@@ -144,9 +149,6 @@ function initSTTPhrase() {
144149
gramList.addFromString(`#JSGF V1.0; grammar activationPhrase; public <activationPhrase> = ${store.speechRecognitionPhraseActivation} ;`, 1);
145150
sttPhrase.value.grammars = gramList;
146151
147-
sttPhrase.value.started = false
148-
sttPhrase.value.addEventListener("start", () => sttPhrase.value.started = true)
149-
150152
sttPhrase.value.onresult = (event) => {
151153
const text = sttPhrase.value.gatherText(event)
152154
@@ -160,15 +162,16 @@ function initSTTPhrase() {
160162
}
161163
}
162164
}
163-
sttPhrase.value.onend = () => {
165+
166+
sttPhrase.value.addEventListener("end", () => {
164167
165168
if(speechRecognitionPhraseActivated.value) { // that means we programmatically ended the SR because we detected the activation phrase
166169
speechRecognitionPhraseActivated.value = false
167170
stt.value.start();
168171
} else {
169172
sttPhrase.value.start();
170173
}
171-
}
174+
})
172175
sttPhrase.value.start();
173176
}
174177

0 commit comments

Comments
 (0)