Add option to speech-recognition streaming mode to include or not the triggers words in the message.

This commit is contained in:
Tony Ribeiro 2023-08-29 03:28:02 +02:00
parent 030424d034
commit feb2383f64
2 changed files with 21 additions and 1 deletions

View File

@ -72,8 +72,11 @@ async function moduleWorker() {
} }
else { else {
console.debug(DEBUG_PREFIX+"Found trigger word: ", triggerWord, " at index ", triggerPos); 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; 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{ else{
userMessageFormatted = userMessageFormatted.substring(messageStart); 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); processTranscript(userMessageFormatted);
} }
} }

View File

@ -14,6 +14,7 @@ class StreamingSttProvider {
triggerWordsText: "", triggerWordsText: "",
triggerWords : [], triggerWords : [],
triggerWordsEnabled : false, triggerWordsEnabled : false,
triggerWordsIncluded: false,
debug : false, debug : false,
} }
@ -26,6 +27,10 @@ class StreamingSttProvider {
<input type="checkbox" id="speech_recognition_streaming_trigger_words_enabled" name="speech_recognition_trigger_words_enabled">\ <input type="checkbox" id="speech_recognition_streaming_trigger_words_enabled" name="speech_recognition_trigger_words_enabled">\
<small>Enable trigger words</small>\ <small>Enable trigger words</small>\
</label>\ </label>\
<label class="checkbox_label" for="speech_recognition_trigger_words_included">\
<input type="checkbox" id="speech_recognition_trigger_words_included" name="speech_recognition_trigger_words_included">\
<small>Include trigger words in message</small>\
</label>\
<label class="checkbox_label" for="speech_recognition_streaming_debug">\ <label class="checkbox_label" for="speech_recognition_streaming_debug">\
<input type="checkbox" id="speech_recognition_streaming_debug" name="speech_recognition_streaming_debug">\ <input type="checkbox" id="speech_recognition_streaming_debug" name="speech_recognition_streaming_debug">\
<small>Enable debug pop ups</small>\ <small>Enable debug pop ups</small>\
@ -42,6 +47,7 @@ class StreamingSttProvider {
array = array.filter((str) => str !== ''); array = array.filter((str) => str !== '');
this.settings.triggerWords = array; this.settings.triggerWords = array;
this.settings.triggerWordsEnabled = $("#speech_recognition_streaming_trigger_words_enabled").is(':checked'); this.settings.triggerWordsEnabled = $("#speech_recognition_streaming_trigger_words_enabled").is(':checked');
this.settings.triggerWordsIncluded = $("#speech_recognition_trigger_words_included").is(':checked');
this.settings.debug = $("#speech_recognition_streaming_debug").is(':checked'); this.settings.debug = $("#speech_recognition_streaming_debug").is(':checked');
console.debug(DEBUG_PREFIX+" Updated settings: ", this.settings); console.debug(DEBUG_PREFIX+" Updated settings: ", this.settings);
this.loadSettings(this.settings); this.loadSettings(this.settings);
@ -66,6 +72,7 @@ class StreamingSttProvider {
$("#speech_recognition_streaming_trigger_words").val(this.settings.triggerWordsText); $("#speech_recognition_streaming_trigger_words").val(this.settings.triggerWordsText);
$("#speech_recognition_streaming_trigger_words_enabled").prop('checked',this.settings.triggerWordsEnabled); $("#speech_recognition_streaming_trigger_words_enabled").prop('checked',this.settings.triggerWordsEnabled);
$("#speech_recognition_trigger_words_included").prop('checked',this.settings.triggerWordsIncluded);
$("#speech_recognition_streaming_debug").prop('checked',this.settings.debug); $("#speech_recognition_streaming_debug").prop('checked',this.settings.debug);
console.debug(DEBUG_PREFIX+"streaming STT settings loaded") console.debug(DEBUG_PREFIX+"streaming STT settings loaded")