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 {
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);
}
}