Skip to content

Commit 4d77bb5

Browse files
committed
widget interim results now are configurable for performance reasons
1 parent 8ec2558 commit 4d77bb5

File tree

8 files changed

+40
-11
lines changed

8 files changed

+40
-11
lines changed

admin/components/widget_config/WidgetConfig.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'speech_recognition_always_on',
4949
'speech_recognition_phrase_activation',
5050
'speech_recognition_beep',
51+
'speech_recognition_interim_results',
5152
'speech_synthesis',
5253
'speech_synthesis_pitch',
5354
'speech_synthesis_rate',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.19 on 2025-03-25 15:54
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("widget", "0036_alter_historicalwidget_domain_alter_widget_domain"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="historicalwidget",
15+
name="speech_recognition_interim_results",
16+
field=models.BooleanField(default=False),
17+
),
18+
migrations.AddField(
19+
model_name="widget",
20+
name="speech_recognition_interim_results",
21+
field=models.BooleanField(default=False),
22+
),
23+
]

back/back/apps/widget/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class Widget(models.Model):
6565
speech_recognition_auto_send = models.BooleanField(default=False)
6666
speech_recognition_phrase_activation = models.CharField(max_length=255, null=True, blank=True)
6767
speech_recognition_beep = models.BooleanField(default=False)
68+
speech_recognition_interim_results = models.BooleanField(default=False)
69+
6870
# # out
6971
speech_synthesis = models.BooleanField(default=False)
7072
speech_synthesis_pitch = models.FloatField(default=1.0, validators=[MinValueValidator(0.0), MaxValueValidator(2.0)])

widget/components/Widget.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const props = defineProps({
8282
speechRecognitionAlwaysOn: Boolean,
8383
speechRecognitionBeep: Boolean,
8484
speechRecognitionPhraseActivation: String,
85+
speechRecognitionInterimResults: Boolean,
8586
allowAttachments: Boolean,
8687
authToken: String,
8788
disableDayNightMode: Boolean,
@@ -170,6 +171,7 @@ function initStore() {
170171
store.speechRecognitionAlwaysOn = data.speechRecognitionAlwaysOn && !data.speechRecognitionPhraseActivation
171172
store.speechRecognitionAutoSend = data.speechRecognitionAutoSend || data.speechRecognitionAlwaysOn
172173
store.speechRecognitionPhraseActivation = !data.speechRecognitionAlwaysOn ? data.speechRecognitionPhraseActivation : undefined
174+
store.speechRecognitionInterimResults = data.speechRecognitionInterimResults
173175
store.speechRecognitionBeep = data.speechRecognitionBeep
174176
store.allowAttachments = data.allowAttachments
175177
store.authToken = data.authToken

widget/components/chat/PromptControls.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ onMounted(async () => {
7070
7171
})
7272
73-
function _initSTT(continuous = false, phrase = false) {
73+
function _initSTT(phrase = false) {
7474
const sr = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
7575
const _type = phrase ? 'Phrase activation' : 'Transcriber'
7676
sr.lang = store.speechRecognitionLang;
77-
sr.continuous = continuous;
78-
sr.interimResults = true;
77+
sr.continuous = false;
78+
sr.interimResults = store.speechRecognitionInterimResults;
7979
sr.maxAlternatives = 1;
8080
sr.started = false;
8181
@@ -85,16 +85,16 @@ function _initSTT(continuous = false, phrase = false) {
8585
sr.addEventListener("start", () => {
8686
sr.started = true;
8787
if (window.speechDebug)
88-
console.log(`STT ${ _type } started`, 'color: #ffcc00');
88+
console.log(`%c STT ${ _type } started`, 'color: #ffcc00');
8989
})
9090
sr.addEventListener("end", () => {
9191
sr.started = false;
9292
if (window.speechDebug)
93-
console.log(`STT ${ _type } finished`, 'color: #ffcc00');
93+
console.log(`%c STT ${ _type } finished`, 'color: #ffcc00');
9494
})
9595
9696
sr.onerror = (event) => {
97-
console.log(`Error occurred in the speech recognition: ${ _type } `, event)
97+
console.log(`%c Error occurred in the speech recognition: ${ _type } `, 'color: #ff0000', event)
9898
// Don't restart if we got a not-allowed error, usually because the user has not granted permission
9999
if (event.error === 'not-allowed') {
100100
store.speechRecognition = false; // Disable speech recognition entirely
@@ -151,7 +151,7 @@ function initSTT() {
151151
}
152152
153153
function initSTTPhrase() {
154-
sttPhrase.value = _initSTT(true, true);
154+
sttPhrase.value = _initSTT(true);
155155
156156
sttPhrase.value.onresult = (event) => {
157157
const text = sttPhrase.value.gatherText(event)
@@ -177,7 +177,7 @@ function initSTTPhrase() {
177177
}
178178
})
179179
if (window.speechDebug)
180-
console.log(`starting phrase activation SR... `, 'color: #ffcc00');
180+
console.log(`%c starting phrase activation SR... `, 'color: #ffcc00');
181181
sttPhrase.value.start();
182182
}
183183

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.4",
3+
"version": "0.2.6",
44
"private": false,
55
"main": "./dist/chatfaq-widget.umd.cjs",
66
"module": "./dist/chatfaq-widget.mjs",

widget/store/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const useGlobalStore = defineStore('globalStore', {
4747
speechRecognitionAlwaysOn: false,
4848
speechRecognitionLang: 'en-US',
4949
speechRecognitionPhraseActivation: undefined,
50+
speechRecognitionInterimResults: false,
5051
speechRecognitionBeep: false,
5152
allowAttachments: false,
5253
authToken: undefined,

0 commit comments

Comments
 (0)