66 speechRecognitionPhraseActivated = true
77 sttPhrase.stop()
88 } else {
9- stt.value. start();
9+ stt.start();
1010 }
1111 }
1212 }" >
@@ -62,7 +62,6 @@ const emit = defineEmits(['send', 'text'])
6262onMounted (async () => {
6363 if (! store .speechRecognition )
6464 return
65-
6665 initSTT ();
6766 if (store .speechRecognitionPhraseActivation )
6867 initSTTPhrase ();
@@ -71,8 +70,9 @@ onMounted(async () => {
7170
7271})
7372
74- function _initSTT (continuous = false ) {
73+ function _initSTT (continuous = false , phrase = false ) {
7574 const sr = new (window .SpeechRecognition || window .webkitSpeechRecognition )();
75+ const _type = phrase ? ' Phrase activation' : ' Transcriber'
7676 sr .lang = store .speechRecognitionLang ;
7777 sr .continuous = continuous;
7878 sr .interimResults = true ;
@@ -82,11 +82,19 @@ function _initSTT(continuous = false) {
8282 sr .addEventListener (" audioend" , sr .stop )
8383 sr .addEventListener (" soundend" , sr .stop )
8484 sr .addEventListener (" speechend" , sr .stop )
85- sr .addEventListener (" start" , () => sr .started = true )
86- sr .addEventListener (" end" , () => sr .started = false )
85+ sr .addEventListener (" start" , () => {
86+ sr .started = true ;
87+ if (window .speechDebug )
88+ console .log (` STT ${ _type } started` )
89+ })
90+ sr .addEventListener (" end" , () => {
91+ sr .started = false ;
92+ if (window .speechDebug )
93+ console .log (` STT ${ _type } finished` )
94+ })
8795
8896 sr .onerror = (event ) => {
89- console .log (' Error occurred in the speech recognition:' , event )
97+ console .log (` Error occurred in the speech recognition: ${ _type } ` , event )
9098 // Don't restart if we got a not-allowed error, usually because the user has not granted permission
9199 if (event .error === ' not-allowed' ) {
92100 store .speechRecognition = false ; // Disable speech recognition entirely
@@ -143,11 +151,7 @@ function initSTT() {
143151}
144152
145153function initSTTPhrase () {
146- sttPhrase .value = _initSTT ();
147-
148- const gramList = new (window .SpeechGrammarList || window .webkitSpeechGrammarList )();
149- gramList .addFromString (` #JSGF V1.0; grammar activationPhrase; public <activationPhrase> = ${ store .speechRecognitionPhraseActivation } ;` , 1 );
150- sttPhrase .value .grammars = gramList;
154+ sttPhrase .value = _initSTT (true , true );
151155
152156 sttPhrase .value .onresult = (event ) => {
153157 const text = sttPhrase .value .gatherText (event )
@@ -172,7 +176,8 @@ function initSTTPhrase() {
172176 sttPhrase .value .start ();
173177 }
174178 })
175- sttPhrase .value .start ();
179+ console .log (" starting phrase activation SR..." )
180+ // sttPhrase.value.start();
176181}
177182
178183// ---------------------------------------- UTILS ----------------------------------------
0 commit comments