Skip to content

Commit 31fbbc0

Browse files
committed
Small bugfix on manually starting STT
1 parent 8476bc9 commit 31fbbc0

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

widget/components/chat/PromptControls.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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'])
6262
onMounted(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
145153
function 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 ----------------------------------------

widget/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

widget/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chatfaq-widget",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"private": false,
55
"main": "./dist/chatfaq-widget.umd.cjs",
66
"module": "./dist/chatfaq-widget.mjs",

0 commit comments

Comments
 (0)