From feb2383f64fe8d331f44075844d14e1d3585a6de Mon Sep 17 00:00:00 2001 From: Tony Ribeiro Date: Tue, 29 Aug 2023 03:28:02 +0200 Subject: [PATCH] Add option to speech-recognition streaming mode to include or not the triggers words in the message. --- .../extensions/speech-recognition/index.js | 15 ++++++++++++++- .../extensions/speech-recognition/streaming.js | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/speech-recognition/index.js b/public/scripts/extensions/speech-recognition/index.js index 8678b6bcd..1ac098f36 100644 --- a/public/scripts/extensions/speech-recognition/index.js +++ b/public/scripts/extensions/speech-recognition/index.js @@ -72,8 +72,11 @@ async function moduleWorker() { } else { console.debug(DEBUG_PREFIX+"Found trigger word: ", triggerWord, " at index ", triggerPos); - if (triggerPos < messageStart | messageStart == -1) { // & (triggerPos + triggerWord.length) < userMessageFormatted.length)) { + if (triggerPos < messageStart || messageStart == -1) { // & (triggerPos + triggerWord.length) < userMessageFormatted.length)) { messageStart = triggerPos; // + triggerWord.length + 1; + + if (!extension_settings.speech_recognition.Streaming.triggerWordsIncluded) + messageStart = triggerPos + triggerWord.length + 1; } } } @@ -93,6 +96,16 @@ async function moduleWorker() { } else{ userMessageFormatted = userMessageFormatted.substring(messageStart); + // Trim non alphanumeric character from the start + messageStart = 0; + for(const i of userMessageFormatted) { + if(/^[a-z]$/i.test(i)) { + break; + } + messageStart += 1; + } + userMessageFormatted = userMessageFormatted.substring(messageStart); + userMessageFormatted = userMessageFormatted.charAt(0).toUpperCase() + userMessageFormatted.substring(1); processTranscript(userMessageFormatted); } } diff --git a/public/scripts/extensions/speech-recognition/streaming.js b/public/scripts/extensions/speech-recognition/streaming.js index 0ef41235c..2dc5d24c9 100644 --- a/public/scripts/extensions/speech-recognition/streaming.js +++ b/public/scripts/extensions/speech-recognition/streaming.js @@ -14,6 +14,7 @@ class StreamingSttProvider { triggerWordsText: "", triggerWords : [], triggerWordsEnabled : false, + triggerWordsIncluded: false, debug : false, } @@ -26,6 +27,10 @@ class StreamingSttProvider { \ Enable trigger words\ \ + \