From 79dcfa6c513127b84b258604b21a9b141d2e5786 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 1 Sep 2023 17:58:33 +0300 Subject: [PATCH] #1077 Add ability to set default voice --- public/scripts/extensions/tts/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index 8b6866035..77c9f7373 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -22,6 +22,8 @@ let lastGroupId = null let lastChatId = null let lastMessageHash = null +const DEFAULT_VOICE_MARKER = '[Default Voice]'; + export function getPreviewString(lang) { const previewStrings = { 'en-US': 'The quick brown fox jumps over the lazy dog', @@ -460,10 +462,12 @@ async function processTtsQueue() { return; } - if (!voiceMap[char]) { + const voiceMapEntry = voiceMap[char] || voiceMap[DEFAULT_VOICE_MARKER] + + if (!voiceMapEntry) { throw `${char} not in voicemap. Configure character in extension settings voice map` } - const voice = await ttsProvider.getVoice((voiceMap[char])) + const voice = await ttsProvider.getVoice(voiceMapEntry) const voiceId = voice.voice_id if (voiceId == null) { toastr.error(`Specified voice for ${char} was not found. Check the TTS extension settings.`) @@ -636,10 +640,12 @@ function getCharacters(){ let characters = [] if (context.groupId === null){ // Single char chat + characters.push(DEFAULT_VOICE_MARKER) characters.push(context.name1) characters.push(context.name2) } else { // Group chat + characters.push(DEFAULT_VOICE_MARKER) characters.push(context.name1) const group = context.groups.find(group => context.groupId == group.id) for (let member of group.members) {