1
1
<template >
2
2
<div v-if =" store.speechRecognition && (!store.promptWithText || store.speechRecognitionTranscribing)" :class =" {'dark-mode': store.darkMode}" class =" prompt-right-button"
3
3
@click =" () => {
4
- if (activeMicro)
5
- if (sttPhrase && sttPhrase.started){
4
+ if (activeMicro) {
5
+ if (sttPhrase && sttPhrase.started) {
6
6
speechRecognitionPhraseActivated = true
7
7
sttPhrase.stop()
8
+ } else {
9
+ stt.value.start();
8
10
}
9
- stt.start()
11
+ }
10
12
}" >
11
13
<div v-if =" store.speechRecognitionTranscribing" class =" micro-anim-elm has-scale-animation" ></div >
12
14
<div v-if =" store.speechRecognitionTranscribing" class =" micro-anim-elm has-scale-animation has-delay-short" ></div >
@@ -75,10 +77,13 @@ function _initSTT(continuous = false) {
75
77
sr .continuous = continuous;
76
78
sr .interimResults = true ;
77
79
sr .maxAlternatives = 1 ;
80
+ sr .started = false ;
78
81
79
82
sr .addEventListener (" audioend" , sr .stop )
80
83
sr .addEventListener (" soundend" , sr .stop )
81
84
sr .addEventListener (" speechend" , sr .stop )
85
+ sr .addEventListener (" start" , () => sr .started = true )
86
+ sr .addEventListener (" end" , () => sr .started = false )
82
87
83
88
sr .onerror = (event ) => {
84
89
console .log (' Error occurred in the speech recognition:' , event )
@@ -123,7 +128,7 @@ function initSTT() {
123
128
if (window .speechDebug )
124
129
console .log (` %c ${ text} ` , " color: #00FF00" );
125
130
}
126
- stt .value .onend = () => {
131
+ stt .value .addEventListener ( " end " , () => {
127
132
store .speechRecognitionTranscribing = false ;
128
133
129
134
if (store .speechRecognitionBeep )
@@ -134,7 +139,7 @@ function initSTT() {
134
139
135
140
if (store .speechRecognitionPhraseActivation )
136
141
sttPhrase .value .start ();
137
- }
142
+ })
138
143
}
139
144
140
145
function initSTTPhrase () {
@@ -144,9 +149,6 @@ function initSTTPhrase() {
144
149
gramList .addFromString (` #JSGF V1.0; grammar activationPhrase; public <activationPhrase> = ${ store .speechRecognitionPhraseActivation } ;` , 1 );
145
150
sttPhrase .value .grammars = gramList;
146
151
147
- sttPhrase .value .started = false
148
- sttPhrase .value .addEventListener (" start" , () => sttPhrase .value .started = true )
149
-
150
152
sttPhrase .value .onresult = (event ) => {
151
153
const text = sttPhrase .value .gatherText (event )
152
154
@@ -160,15 +162,16 @@ function initSTTPhrase() {
160
162
}
161
163
}
162
164
}
163
- sttPhrase .value .onend = () => {
165
+
166
+ sttPhrase .value .addEventListener (" end" , () => {
164
167
165
168
if (speechRecognitionPhraseActivated .value ) { // that means we programmatically ended the SR because we detected the activation phrase
166
169
speechRecognitionPhraseActivated .value = false
167
170
stt .value .start ();
168
171
} else {
169
172
sttPhrase .value .start ();
170
173
}
171
- }
174
+ })
172
175
sttPhrase .value .start ();
173
176
}
174
177
0 commit comments