Support for AllTalk V1 and V2 Select the version in the interface. RVC is not supported on AllTalk V1
Signed| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { doExtrasFetch, getApiUrl, modules } from '../../extensions.js'; |
| 2 | 2 | import { saveTtsProviderSettings } from './index.js'; |
| 3 | 3 | |
| 4 | 4 | export { AllTalkTtsProvider }; |
| @@ -13,22 +13,29 @@ class AllTalkTtsProvider { | ||
| 13 | 13 | // Initialize with default settings if they are not already set |
| 14 | 14 | this.settings = { |
| 15 | 15 | provider_endpoint: this.settings.provider_endpoint || 'http://localhost:7851', |
| 16 | + server_version: this.settings.server_version || 'v2', | |
| 16 | 17 | language: this.settings.language || 'en', |
| 17 | 18 | voiceMap: this.settings.voiceMap || {}, |
| 18 | 19 | at_generation_method: this.settings.at_generation_method || 'standard_generation', |
| 19 | 20 | narrator_enabled: this.settings.narrator_enabled || 'false', |
| 20 | 21 | at_narrator_text_not_inside: this.settings.at_narrator_text_not_inside || 'narrator', |
| 21 | 22 | narrator_voice_gen: this.settings.narrator_voice_gen || 'female_01.wavPlease set a voice', |
| 22 | 23 | finetuned_modelrvc_character_voice: this.settings.finetuned_modelrvc_character_voice || 'falseDisabled', |
| 24 | + rvc_character_pitch: this.settings.rvc_character_pitch || '0', | |
| 25 | + rvc_narrator_voice: this.settings.rvc_narrator_voice || 'Disabled', | |
| 26 | + rvc_narrator_pitch: this.settings.rvc_narrator_pitch || '0', | |
| 27 | + finetuned_model: this.settings.finetuned_model || 'false' | |
| 23 | 28 | }; |
| 24 | 29 | // Separate property for dynamically updated settings from the server |
| 25 | 30 | this.dynamicSettings = { |
| 26 | 31 | modelsAvailable: [], |
| 27 | 32 | currentModel: '', |
| 28 | 33 | deepspeed_available: false, |
| 29 | 34 | deepSpeedEnableddeepspeed_enabled: false, |
| 30 | 35 | lowVramEnabledlowvram_capable: false, |
| 36 | + lowvram_enabled: false, | |
| 31 | 37 | }; |
| 38 | + this.rvcVoices = []; // Initialize rvcVoices as an empty array | |
| 32 | 39 | } |
| 33 | 40 | ready = false; |
| 34 | 41 | voices = []; |
| @@ -56,7 +63,7 @@ class AllTalkTtsProvider { | ||
| 56 | 63 | }; |
| 57 | 64 | |
| 58 | 65 | get settingsHtml() { |
| 59 | 66 | let html = '`<div class="at-settings-separator">AllTalk V2 Settings</div>'`; |
| 60 | 67 | |
| 61 | 68 | html += `<div class="at-settings-row"> |
| 62 | 69 | |
| @@ -75,6 +82,7 @@ class AllTalkTtsProvider { | ||
| 75 | 82 | <label for="at_narrator_enabled">AT Narrator</label> |
| 76 | 83 | <select id="at_narrator_enabled"> |
| 77 | 84 | <option value="true">Enabled</option> |
| 85 | + <option value="silent">Enabled (Silenced)</option> | |
| 78 | 86 | <option value="false">Disabled</option> |
| 79 | 87 | </select> |
| 80 | 88 | </div> |
| @@ -82,8 +90,9 @@ class AllTalkTtsProvider { | ||
| 82 | 90 | <div class="at-settings-option"> |
| 83 | 91 | <label for="at_narrator_text_not_inside">Text Not Inside * or " is</label> |
| 84 | 92 | <select id="at_narrator_text_not_inside"> |
| 85 | - <option value="narrator">Narrator</option> | |
| 86 | 93 | <option value="character">Character</option> |
| 94 | + <option value="narrator">Narrator</option> | |
| 95 | + <option value="silent">Silent</option> | |
| 87 | 96 | </select> |
| 88 | 97 | </div> |
| 89 | 98 | |
| @@ -110,27 +119,74 @@ class AllTalkTtsProvider { | ||
| 110 | 119 | </div> |
| 111 | 120 | </div>`; |
| 112 | 121 | |
| 122 | + html += `<div class="at-settings-row"> | |
| 123 | + <div class="at-settings-option"> | |
| 124 | + <label for="rvc_character_voice">RVC Character</label> | |
| 125 | + <select id="rvc_character_voice">`; | |
| 126 | + if (this.rvcVoices) { | |
| 127 | + for (let rvccharvoice of this.rvcVoices) { | |
| 128 | + html += `<option value="${rvccharvoice.voice_id}">${rvccharvoice.name}</option>`; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + html += `</select> | |
| 132 | + </div> | |
| 133 | + <div class="at-settings-option"> | |
| 134 | + <label for="rvc_narrator_voice">RVC Narrator</label> | |
| 135 | + <select id="rvc_narrator_voice">`; | |
| 136 | + if (this.rvcVoices) { | |
| 137 | + for (let rvcnarrvoice of this.rvcVoices) { | |
| 138 | + html += `<option value="${rvcnarrvoice.voice_id}">${rvcnarrvoice.name}</option>`; | |
| 139 | + } | |
| 140 | + } | |
| 141 | + html += `</select> | |
| 142 | + </div> | |
| 143 | +</div>`; | |
| 144 | + | |
| 145 | + // Add the RVC pitch control row | |
| 146 | + html += `<div class="at-settings-row"> | |
| 147 | + <div class="at-settings-option"> | |
| 148 | + <label for="rvc_character_pitch">RVC Character Pitch</label> | |
| 149 | + <select id="rvc_character_pitch">`; | |
| 150 | + for (let i = -24; i <= 24; i++) { | |
| 151 | + const selected = i === 0 ? 'selected="selected"' : ''; | |
| 152 | + html += `<option value="${i}" ${selected}>${i}</option>`; | |
| 153 | + } | |
| 154 | + html += `</select> | |
| 155 | + </div> | |
| 156 | + <div class="at-settings-option"> | |
| 157 | + <label for="rvc_narrator_pitch">RVC Narrator Pitch</label> | |
| 158 | + <select id="rvc_narrator_pitch">`; | |
| 159 | + for (let i = -24; i <= 24; i++) { | |
| 160 | + const selected = i === 0 ? 'selected="selected"' : ''; | |
| 161 | + html += `<option value="${i}" ${selected}>${i}</option>`; | |
| 162 | + } | |
| 163 | + html += `</select> | |
| 164 | + </div> | |
| 165 | + </div>`; | |
| 113 | 166 | |
| 114 | 167 | html += `<div class="at-model-endpoint-row"> |
| 115 | 168 | <div class="at-model-option"> |
| 116 | 169 | <label for="switch_model">Switch Model</label> |
| 117 | 170 | <select id="switch_model"> |
| 118 | - <option value="api_tts">API TTS</option> | |
| 171 | + <!-- Options will be dynamically populated --> | |
| 119 | - <option value="api_local">API Local</option> | |
| 120 | - <option value="xttsv2_local">XTTSv2 Local</option> | |
| 121 | 172 | </select> |
| 122 | 173 | </div> |
| 123 | - </div> | |
| 124 | - | |
| 125 | - <div class="at-model-endpoint-row"> | |
| 126 | 174 | |
| 127 | 175 | <div class="at-endpoint-option"> |
| 128 | 176 | <label for="at_server">AllTalk Endpoint:</label> |
| 129 | 177 | <input id="at_server" type="text" class="text_pole" maxlength="80" value="${this.settings.provider_endpoint}"/> |
| 130 | - <i><b>Important:</b> Must match IP address & port in AllTalk settings.</i> | |
| 131 | 178 | </div> |
| 132 | 179 | </div>`; |
| 133 | 180 | |
| 181 | + html += `<div class="at-settings-row"> | |
| 182 | + <div class="at-settings-option"> | |
| 183 | + <label for="server_version">AllTalk Server Version</label> | |
| 184 | + <select id="server_version"> | |
| 185 | + <option value="v1">AllTalk V1</option> | |
| 186 | + <option value="v2">AllTalk V2</option> | |
| 187 | + </select> | |
| 188 | + </div> | |
| 189 | + </div>`; | |
| 134 | 190 | |
| 135 | 191 | html += `<div class="at-model-endpoint-row"> |
| 136 | 192 | <div class="at-settings-option"> |
| @@ -152,7 +208,7 @@ class AllTalkTtsProvider { | ||
| 152 | 208 | |
| 153 | 209 | html += `<div class="at-website-row"> |
| 154 | 210 | <div class="at-website-option"> |
| 155 | 211 | <span>AllTalk V2<a target="_blank" href="${this.settings.provider_endpoint}">Config & Docs</a>.</span> |
| 156 | 212 | </div> |
| 157 | 213 | |
| 158 | 214 | <div class="at-website-option"> |
| @@ -162,7 +218,9 @@ class AllTalkTtsProvider { | ||
| 162 | 218 | |
| 163 | 219 | html += `<div class="at-website-row"> |
| 164 | 220 | <div class="at-website-option"> |
| 165 | -<span><strong>Text-generation-webui</strong> users - Uncheck <strong>Enable TTS</strong> in Text-generation-webui.</span> | |
| 221 | +<span>- If you <strong>change your TTS engine</strong> in AllTalk, you will need to <strong>Reload</strong> (button above) and re-select your voices.</span><br><br> | |
| 222 | +<span>- Assuming the server is <strong>Status: Ready</strong>, most problems will be resolved by hitting Reload and selecting voices that match the loaded TTS engine.</span><br><br> | |
| 223 | +<span>- <strong>Text-generation-webui</strong> users - Uncheck <strong>Enable TTS</strong> in the TGWUI interface, or you will hear 2x voices and file names being generated.</span> | |
| 166 | 224 | </div> |
| 167 | 225 | </div>`; |
| 168 | 226 | |
| @@ -193,35 +251,35 @@ class AllTalkTtsProvider { | ||
| 193 | 251 | // Update UI elements to reflect the loaded settings |
| 194 | 252 | $('#at_server').val(this.settings.provider_endpoint); |
| 195 | 253 | $('#language_options').val(this.settings.language); |
| 196 | - //$('#voicemap').val(this.settings.voiceMap); | |
| 197 | 254 | $('#at_generation_method').val(this.settings.at_generation_method); |
| 198 | 255 | $('#at_narrator_enabled').val(this.settings.narrator_enabled); |
| 199 | 256 | $('#at_narrator_text_not_inside').val(this.settings.at_narrator_text_not_inside); |
| 200 | 257 | $('#narrator_voice').val(this.settings.narrator_voice_gen); |
| 258 | + $('#rvc_character_voice').val(this.settings.rvc_character_voice); | |
| 259 | + $('#rvc_narrator_voice').val(this.settings.rvc_narrator_voice); | |
| 260 | + $('#rvc_character_pitch').val(this.settings.rvc_character_pitch); | |
| 261 | + $('#rvc_narrator_pitch').val(this.settings.rvc_narrator_pitch); | |
| 201 | 262 | |
| 202 | 263 | console.debug('AllTalkTTS: Settings loaded'); |
| 203 | - await this.initEndpoint(); | |
| 204 | - } | |
| 205 | - | |
| 206 | - async initEndpoint() { | |
| 207 | 264 | try { |
| 208 | 265 | // Check if TTS provider is ready |
| 209 | - this.setupEventListeners(); | |
| 210 | - this.updateLanguageDropdown(); | |
| 211 | 266 | await this.checkReady(); |
| 212 | 267 | await this.updateSettingsFromServer(); // Fetch dynamic settings from the TTS server |
| 213 | 268 | await this.fetchTtsVoiceObjects(); // Fetch voices only if service is ready |
| 269 | + await this.fetchRvcVoiceObjects(); // Fetch RVC voices | |
| 214 | 270 | this.updateNarratorVoicesDropdown(); |
| 271 | + this.updateLanguageDropdown(); | |
| 272 | + this.setupEventListeners(); | |
| 215 | 273 | this.applySettingsToHTML(); |
| 216 | 274 | updateStatus('Ready'); |
| 217 | 275 | } catch (error) { |
| 218 | 276 | console.error('"Error loading settings:'", error); |
| 219 | 277 | updateStatus('Offline'); |
| 220 | 278 | } |
| 221 | 279 | } |
| 222 | 280 | |
| 281 | + | |
| 223 | 282 | applySettingsToHTML() { |
| 224 | - // Apply loaded settings or use defaults | |
| 225 | 283 | const narratorVoiceSelect = document.getElementById('narrator_voice'); |
| 226 | 284 | const atNarratorSelect = document.getElementById('at_narrator_enabled'); |
| 227 | 285 | const textNotInsideSelect = document.getElementById('at_narrator_text_not_inside'); |
| @@ -229,30 +287,26 @@ class AllTalkTtsProvider { | ||
| 229 | 287 | this.settings.narrator_voice = this.settings.narrator_voice_gen; |
| 230 | 288 | // Apply settings to Narrator Voice dropdown |
| 231 | 289 | if (narratorVoiceSelect && this.settings.narrator_voice) { |
| 232 | 290 | narratorVoiceSelect.value = this.settings.narrator_voice.replace('.wav', ''); // Remove the parentheses |
| 233 | 291 | } |
| 234 | 292 | // Apply settings to AT Narrator Enabled dropdown |
| 235 | 293 | if (atNarratorSelect) { |
| 236 | - // Sync the state with the checkbox in index.js | |
| 294 | + const ttsPassAsterisksCheckbox = document.getElementById('tts_pass_asterisks'); | |
| 237 | 295 | const ttsPassAsterisksCheckboxttsNarrateQuotedCheckbox = document.getElementById('tts_pass_asteriskstts_narrate_quoted'); // Access the checkbox from index.js |
| 238 | 296 | const ttsNarrateQuotedCheckboxttsNarrateDialoguesCheckbox = document.getElementById('tts_narrate_quotedtts_narrate_dialogues'); // Access the checkbox from index.js |
| 239 | - const ttsNarrateDialoguesCheckbox = document.getElementById('tts_narrate_dialogues'); // Access the checkbox from index.js | |
| 240 | - // Sync the state with the checkbox in index.js | |
| 241 | 297 | if (this.settings.narrator_enabled) { |
| 242 | 298 | ttsPassAsterisksCheckbox.checked = false; |
| 243 | 299 | $('#tts_pass_asterisks').click(); // Simulate a click event |
| 244 | 300 | $('#tts_pass_asterisks').trigger('change'); |
| 245 | 301 | } |
| 246 | 302 | if (!this.settings.narrator_enabled) { |
| 247 | 303 | ttsPassAsterisksCheckbox.checked = true; |
| 248 | 304 | $('#tts_pass_asterisks').click(); // Simulate a click event |
| 249 | 305 | $('#tts_pass_asterisks').trigger('change'); |
| 250 | 306 | } |
| 251 | - // Uncheck and set tts_narrate_quoted to false if narrator is enabled | |
| 307 | + if (this.settings.narrator_enabled) { | |
| 252 | - if (this.settings.narrator_enabledd) { | |
| 253 | 308 | ttsNarrateQuotedCheckbox.checked = true; |
| 254 | 309 | ttsNarrateDialoguesCheckbox.checked = true; |
| 255 | - // Trigger click events instead of change events | |
| 256 | 310 | $('#tts_narrate_quoted').click(); |
| 257 | 311 | $('#tts_narrate_quoted').trigger('change'); |
| 258 | 312 | $('#tts_narrate_dialogues').click(); |
| @@ -261,42 +315,30 @@ class AllTalkTtsProvider { | ||
| 261 | 315 | atNarratorSelect.value = this.settings.narrator_enabled.toString(); |
| 262 | 316 | this.settings.narrator_enabled = this.settings.narrator_enabled.toString(); |
| 263 | 317 | } |
| 264 | - // Apply settings to the Language dropdown | |
| 265 | 318 | const languageSelect = document.getElementById('language_options'); |
| 266 | 319 | if (languageSelect && this.settings.language) { |
| 267 | 320 | languageSelect.value = this.settings.language; |
| 268 | 321 | } |
| 269 | - // Apply settings to Text Not Inside dropdown | |
| 270 | 322 | if (textNotInsideSelect && this.settings.text_not_inside) { |
| 271 | 323 | textNotInsideSelect.value = this.settings.text_not_inside; |
| 272 | 324 | this.settings.at_narrator_text_not_inside = this.settings.text_not_inside; |
| 273 | 325 | } |
| 274 | - // Apply settings to Generation Method dropdown | |
| 275 | 326 | if (generationMethodSelect && this.settings.at_generation_method) { |
| 276 | 327 | generationMethodSelect.value = this.settings.at_generation_method; |
| 277 | 328 | } |
| 278 | - // Additional logic to disable/enable dropdowns based on the selected generation method | |
| 279 | 329 | const isStreamingEnabled = this.settings.at_generation_method === 'streaming_enabled'; |
| 280 | 330 | if (isStreamingEnabled) { |
| 281 | - // Disable certain dropdowns when streaming is enabled | |
| 282 | 331 | if (atNarratorSelect) atNarratorSelect.disabled = true; |
| 283 | 332 | if (textNotInsideSelect) textNotInsideSelect.disabled = true; |
| 284 | 333 | if (narratorVoiceSelect) narratorVoiceSelect.disabled = true; |
| 285 | 334 | } else { |
| 286 | - // Enable dropdowns for standard generation | |
| 287 | 335 | if (atNarratorSelect) atNarratorSelect.disabled = false; |
| 288 | 336 | if (textNotInsideSelect) textNotInsideSelect.disabled = !this.settings.narrator_enabled; |
| 289 | 337 | if (narratorVoiceSelect) narratorVoiceSelect.disabled = !this.settings.narrator_enabled; |
| 290 | 338 | } |
| 291 | - const modelSelect = document.getElementById('switch_model'); | |
| 292 | - if (this.settings.finetuned_model === 'true') { | |
| 293 | - const ftOption = document.createElement('option'); | |
| 294 | - ftOption.value = 'XTTSv2 FT'; | |
| 295 | - ftOption.textContent = 'XTTSv2 FT'; | |
| 296 | - modelSelect.appendChild(ftOption); | |
| 297 | - } | |
| 298 | 339 | } |
| 299 | 340 | |
| 341 | + | |
| 300 | 342 | //##############################// |
| 301 | 343 | // Check AT Server is Available // |
| 302 | 344 | //##############################// |
| @@ -320,7 +362,6 @@ class AllTalkTtsProvider { | ||
| 320 | 362 | } catch (error) { |
| 321 | 363 | console.error('Error checking TTS service readiness:', error); |
| 322 | 364 | this.ready = false; // Ensure ready flag is set to false in case of error |
| 323 | - throw error; // Rethrow the error for further handling | |
| 324 | 365 | } |
| 325 | 366 | } |
| 326 | 367 | |
| @@ -336,45 +377,149 @@ class AllTalkTtsProvider { | ||
| 336 | 377 | } |
| 337 | 378 | const data = await response.json(); |
| 338 | 379 | const voices = data.voices.map(filename => { |
| 339 | - const voiceName = filename.replace('.wav', ''); | |
| 340 | 380 | return { |
| 341 | 381 | name: voiceNamefilename, |
| 342 | 382 | voice_id: voiceNamefilename, |
| 343 | 383 | preview_url: null, // Preview URL will be dynamically generated |
| 344 | 384 | lang: 'en', // Default language |
| 345 | 385 | }; |
| 346 | 386 | }); |
| 347 | 387 | this.voices = voices; // Assign to the class property |
| 348 | 388 | return voices; // Also return this list |
| 349 | 389 | } |
| 350 | 390 | |
| 391 | + async fetchRvcVoiceObjects() { | |
| 392 | + if (this.settings.server_version !== 'v2') { | |
| 393 | + console.log('Skipping RVC voices fetch for V1 server'); | |
| 394 | + return []; | |
| 395 | + } | |
| 396 | + | |
| 397 | + console.log('Fetching RVC Voices'); | |
| 398 | + try { | |
| 399 | + const response = await fetch(`${this.settings.provider_endpoint}/api/rvcvoices`); | |
| 400 | + if (!response.ok) { | |
| 401 | + const errorText = await response.text(); | |
| 402 | + console.error('Error text:', errorText); | |
| 403 | + throw new Error(`HTTP ${response.status}: ${errorText}`); | |
| 404 | + } | |
| 405 | + | |
| 406 | + const data = await response.json(); | |
| 407 | + if (!data || !data.rvcvoices) { | |
| 408 | + console.error('Invalid data format:', data); | |
| 409 | + throw new Error('Invalid data format received from /api/rvcvoices'); | |
| 410 | + } | |
| 411 | + | |
| 412 | + const voices = data.rvcvoices.map(filename => { | |
| 413 | + return { | |
| 414 | + name: filename, | |
| 415 | + voice_id: filename, | |
| 416 | + }; | |
| 417 | + }); | |
| 418 | + | |
| 419 | + console.log('RVC voices:', voices); | |
| 420 | + this.rvcVoices = voices; // Assign to the class property | |
| 421 | + this.updateRvcVoiceDropdowns(); // Update UI after fetching voices | |
| 422 | + return voices; // Also return this list | |
| 423 | + } catch (error) { | |
| 424 | + console.error('Error fetching RVC voices:', error); | |
| 425 | + this.rvcVoices = [{ name: 'Disabled', voice_id: 'Disabled' }]; // Set default on error | |
| 426 | + throw error; | |
| 427 | + } finally { | |
| 428 | + // Ensure dropdowns are updated even if there was an error | |
| 429 | + this.updateRvcVoiceDropdowns(); | |
| 430 | + } | |
| 431 | + } | |
| 432 | + | |
| 351 | 433 | //##########################################// |
| 352 | 434 | // Get Current AT Server Config & Update ST // |
| 353 | 435 | //##########################################// |
| 354 | 436 | |
| 355 | 437 | async updateSettingsFromServer() { |
| 356 | 438 | try { |
| 357 | - // Fetch current settings | |
| 358 | 439 | const response = await fetch(`${this.settings.provider_endpoint}/api/currentsettings`); |
| 359 | 440 | if (!response.ok) { |
| 360 | 441 | throw new Error(`Failed to fetch current settings: ${response.statusText}`); |
| 361 | 442 | } |
| 362 | 443 | const currentSettings = await response.json(); |
| 363 | - // Update internal settings | |
| 444 | + currentSettings.models_available.sort((a, b) => a.name.localeCompare(b.name)); | |
| 445 | + | |
| 446 | + this.settings.enginesAvailable = currentSettings.engines_available; | |
| 447 | + this.settings.currentEngineLoaded = currentSettings.current_engine_loaded; | |
| 364 | 448 | this.settings.modelsAvailable = currentSettings.models_available; |
| 365 | 449 | this.settings.currentModel = currentSettings.current_model_loaded; |
| 450 | + this.settings.deepspeed_capable = currentSettings.deepspeed_capable; | |
| 366 | 451 | this.settings.deepspeed_available = currentSettings.deepspeed_available; |
| 367 | 452 | this.settings.deepSpeedEnableddeepspeed_enabled = currentSettings.deepspeed_statusdeepspeed_enabled; |
| 368 | 453 | this.settings.lowVramEnabledlowvram_capable = currentSettings.low_vram_statuslowvram_capable; |
| 369 | 454 | this.settings.finetuned_modellowvram_enabled = currentSettings.finetuned_modellowvram_enabled; |
| 370 | - // Update HTML elements | |
| 455 | + | |
| 456 | + await this.fetchRvcVoiceObjects(); // Fetch RVC voices | |
| 457 | + | |
| 371 | 458 | this.updateModelDropdown(); |
| 372 | 459 | this.updateCheckboxes(); |
| 460 | + this.updateRvcVoiceDropdowns(); // Update the RVC voice dropdowns | |
| 373 | 461 | } catch (error) { |
| 374 | 462 | console.error(`Error updating settings from server: ${error}`); |
| 375 | 463 | } |
| 376 | 464 | } |
| 377 | 465 | |
| 466 | + updateRvcVoiceDropdowns() { | |
| 467 | + // Handle all RVC-related elements | |
| 468 | + const rvcElements = document.querySelectorAll('.rvc-setting'); | |
| 469 | + const isV2 = this.settings.server_version === 'v2'; | |
| 470 | + | |
| 471 | + rvcElements.forEach(element => { | |
| 472 | + element.style.display = isV2 ? 'block' : 'none'; | |
| 473 | + }); | |
| 474 | + | |
| 475 | + // Update and disable/enable character voice dropdown | |
| 476 | + const rvcCharacterVoiceSelect = document.getElementById('rvc_character_voice'); | |
| 477 | + if (rvcCharacterVoiceSelect) { | |
| 478 | + rvcCharacterVoiceSelect.disabled = !isV2; | |
| 479 | + if (this.rvcVoices) { | |
| 480 | + rvcCharacterVoiceSelect.innerHTML = ''; | |
| 481 | + for (let voice of this.rvcVoices) { | |
| 482 | + const option = document.createElement('option'); | |
| 483 | + option.value = voice.voice_id; | |
| 484 | + option.textContent = voice.name; | |
| 485 | + if (voice.voice_id === this.settings.rvc_character_voice) { | |
| 486 | + option.selected = true; | |
| 487 | + } | |
| 488 | + rvcCharacterVoiceSelect.appendChild(option); | |
| 489 | + } | |
| 490 | + } | |
| 491 | + } | |
| 492 | + | |
| 493 | + // Update and disable/enable narrator voice dropdown | |
| 494 | + const rvcNarratorVoiceSelect = document.getElementById('rvc_narrator_voice'); | |
| 495 | + if (rvcNarratorVoiceSelect) { | |
| 496 | + rvcNarratorVoiceSelect.disabled = !isV2; | |
| 497 | + if (this.rvcVoices) { | |
| 498 | + rvcNarratorVoiceSelect.innerHTML = ''; | |
| 499 | + for (let voice of this.rvcVoices) { | |
| 500 | + const option = document.createElement('option'); | |
| 501 | + option.value = voice.voice_id; | |
| 502 | + option.textContent = voice.name; | |
| 503 | + if (voice.voice_id === this.settings.rvc_narrator_voice) { | |
| 504 | + option.selected = true; | |
| 505 | + } | |
| 506 | + rvcNarratorVoiceSelect.appendChild(option); | |
| 507 | + } | |
| 508 | + } | |
| 509 | + } | |
| 510 | + | |
| 511 | + // Update pitch inputs | |
| 512 | + const characterPitch = document.getElementById('rvc_character_pitch'); | |
| 513 | + if (characterPitch) { | |
| 514 | + characterPitch.disabled = !isV2; | |
| 515 | + } | |
| 516 | + | |
| 517 | + const narratorPitch = document.getElementById('rvc_narrator_pitch'); | |
| 518 | + if (narratorPitch) { | |
| 519 | + narratorPitch.disabled = !isV2; | |
| 520 | + } | |
| 521 | + } | |
| 522 | + | |
| 378 | 523 | //###################################################// |
| 379 | 524 | // Get Current AT Server Config & Update ST (Models) // |
| 380 | 525 | //###################################################// |
| @@ -385,9 +530,9 @@ class AllTalkTtsProvider { | ||
| 385 | 530 | modelSelect.innerHTML = ''; // Clear existing options |
| 386 | 531 | this.settings.modelsAvailable.forEach(model => { |
| 387 | 532 | const option = document.createElement('option'); |
| 388 | 533 | option.value = model.model_namename; |
| 389 | 534 | option.textContent = model.model_namename; // Use model_name instead ofmodel name directly |
| 390 | 535 | option.selected = model.model_namename === this.settings.currentModel; |
| 391 | 536 | modelSelect.appendChild(option); |
| 392 | 537 | }); |
| 393 | 538 | } |
| @@ -400,13 +545,36 @@ class AllTalkTtsProvider { | ||
| 400 | 545 | updateCheckboxes() { |
| 401 | 546 | const deepspeedCheckbox = document.getElementById('deepspeed'); |
| 402 | 547 | const lowVramCheckbox = document.getElementById('low_vram'); |
| 403 | - if (lowVramCheckbox) lowVramCheckbox.checked = this.settings.lowVramEnabled; | |
| 548 | + | |
| 549 | + // Handle DeepSpeed checkbox | |
| 404 | 550 | if (deepspeedCheckbox) { |
| 405 | - deepspeedCheckbox.checked = this.settings.deepSpeedEnabled; | |
| 551 | + if (this.settings.deepspeed_capable) { | |
| 406 | - deepspeedCheckbox.disabled = !this.settings.deepspeed_available; // Disable checkbox if deepspeed is not available | |
| 552 | + // If TTS engine is capable of using DeepSpeed | |
| 553 | + deepspeedCheckbox.disabled = !this.settings.deepspeed_available; | |
| 554 | + this.settings.deepspeed_enabled = this.settings.deepspeed_available && this.settings.deepspeed_enabled; | |
| 555 | + } else { | |
| 556 | + // If TTS engine is NOT capable of using DeepSpeed | |
| 557 | + deepspeedCheckbox.disabled = true; | |
| 558 | + this.settings.deepspeed_enabled = false; | |
| 407 | 559 | } |
| 560 | + deepspeedCheckbox.checked = this.settings.deepspeed_enabled; | |
| 408 | 561 | } |
| 409 | 562 | |
| 563 | + // Handle Low VRAM checkbox | |
| 564 | + if (lowVramCheckbox) { | |
| 565 | + if (this.settings.lowvram_capable) { | |
| 566 | + // If TTS engine is capable of low VRAM | |
| 567 | + lowVramCheckbox.disabled = false; | |
| 568 | + } else { | |
| 569 | + // If TTS engine is NOT capable of low VRAM | |
| 570 | + lowVramCheckbox.disabled = true; | |
| 571 | + this.settings.lowvram_enabled = false; | |
| 572 | + } | |
| 573 | + lowVramCheckbox.checked = this.settings.lowvram_enabled; | |
| 574 | + } | |
| 575 | + } | |
| 576 | + | |
| 577 | + | |
| 410 | 578 | //###############################################################// |
| 411 | 579 | // Get Current AT Server Config & Update ST (AT Narrator Voices) // |
| 412 | 580 | //###############################################################// |
| @@ -433,8 +601,8 @@ class AllTalkTtsProvider { | ||
| 433 | 601 | updateLanguageDropdown() { |
| 434 | 602 | const languageSelect = document.getElementById('language_options'); |
| 435 | 603 | if (languageSelect) { |
| 436 | 604 | // Ensure default language is set (??? whatever that means) |
| 437 | 605 | // this.settings.language = this.settings.language; |
| 438 | 606 | |
| 439 | 607 | languageSelect.innerHTML = ''; |
| 440 | 608 | for (let language in this.languageLabels) { |
| @@ -456,28 +624,28 @@ class AllTalkTtsProvider { | ||
| 456 | 624 | setupEventListeners() { |
| 457 | 625 | |
| 458 | 626 | let debounceTimeout; |
| 459 | 627 | const debounceDelay = 5001400; // Milliseconds |
| 460 | 628 | |
| 461 | 629 | // Define the event handler function |
| 462 | 630 | const onModelSelectChange = async (event) => { |
| 463 | 631 | console.log('"Model select change event triggered'"); // Debugging statement |
| 464 | 632 | const selectedModel = event.target.value; |
| 465 | 633 | console.log(`Selected model: ${selectedModel}`); // Debugging statement |
| 466 | 634 | // Set status to Processing |
| 467 | 635 | updateStatus('Processing'); |
| 468 | 636 | try { |
| 469 | 637 | const response = await fetch(`${this.settings.provider_endpoint}/api/reload?tts_method=${encodeURIComponent(selectedModel)}`, { |
| 470 | 638 | method: 'POST', |
| 471 | 639 | }); |
| 472 | 640 | if (!response.ok) { |
| 473 | 641 | throw new Error(`HTTP Error: ${response.status}`); |
| 474 | 642 | } |
| 475 | 643 | const data = await response.json(); |
| 476 | 644 | console.log('"POST response data:'", data); // Debugging statement |
| 477 | 645 | // Set status to Ready if successful |
| 478 | 646 | updateStatus('Ready'); |
| 479 | 647 | } catch (error) { |
| 480 | 648 | console.error('"POST request error:'", error); // Debugging statement |
| 481 | 649 | // Set status to Error in case of failure |
| 482 | 650 | updateStatus('Error'); |
| 483 | 651 | } |
| @@ -485,6 +653,52 @@ class AllTalkTtsProvider { | ||
| 485 | 653 | // Handle response or error |
| 486 | 654 | }; |
| 487 | 655 | |
| 656 | + // AllTalk Server version change listener | |
| 657 | + const serverVersionSelect = document.getElementById('server_version'); | |
| 658 | + if (serverVersionSelect) { | |
| 659 | + serverVersionSelect.addEventListener('change', async (event) => { | |
| 660 | + this.settings.server_version = event.target.value; | |
| 661 | + // Clear and refetch voices if needed | |
| 662 | + if (event.target.value === 'v2') { | |
| 663 | + await this.fetchRvcVoiceObjects(); | |
| 664 | + } | |
| 665 | + this.updateRvcVoiceDropdowns(); | |
| 666 | + this.onSettingsChange(); | |
| 667 | + }); | |
| 668 | + } | |
| 669 | + | |
| 670 | + const rvcCharacterVoiceSelect = document.getElementById('rvc_character_voice'); | |
| 671 | + if (rvcCharacterVoiceSelect) { | |
| 672 | + rvcCharacterVoiceSelect.addEventListener('change', (event) => { | |
| 673 | + this.settings.rvccharacter_voice_gen = event.target.value; | |
| 674 | + this.onSettingsChange(); // Save the settings after change | |
| 675 | + }); | |
| 676 | + } | |
| 677 | + | |
| 678 | + const rvcNarratorVoiceSelect = document.getElementById('rvc_narrator_voice'); | |
| 679 | + if (rvcNarratorVoiceSelect) { | |
| 680 | + rvcNarratorVoiceSelect.addEventListener('change', (event) => { | |
| 681 | + this.settings.rvcnarrator_voice_gen = event.target.value; | |
| 682 | + this.onSettingsChange(); // Save the settings after change | |
| 683 | + }); | |
| 684 | + } | |
| 685 | + | |
| 686 | + const rvcCharacterPitchSelect = document.getElementById('rvc_character_pitch'); | |
| 687 | + if (rvcCharacterPitchSelect) { | |
| 688 | + rvcCharacterPitchSelect.addEventListener('change', (event) => { | |
| 689 | + this.settings.rvc_character_pitch = event.target.value; | |
| 690 | + this.onSettingsChange(); // Save the settings after change | |
| 691 | + }); | |
| 692 | + } | |
| 693 | + | |
| 694 | + const rvcNarratorPitchSelect = document.getElementById('rvc_narrator_pitch'); | |
| 695 | + if (rvcNarratorPitchSelect) { | |
| 696 | + rvcNarratorPitchSelect.addEventListener('change', (event) => { | |
| 697 | + this.settings.rvc_narrator_pitch = event.target.value; | |
| 698 | + this.onSettingsChange(); // Save the settings after change | |
| 699 | + }); | |
| 700 | + } | |
| 701 | + | |
| 488 | 702 | const debouncedModelSelectChange = (event) => { |
| 489 | 703 | clearTimeout(debounceTimeout); |
| 490 | 704 | debounceTimeout = setTimeout(() => { |
| @@ -496,74 +710,89 @@ class AllTalkTtsProvider { | ||
| 496 | 710 | const modelSelect = document.getElementById('switch_model'); |
| 497 | 711 | if (modelSelect) { |
| 498 | 712 | // Remove the event listener if it was previously added |
| 713 | + modelSelect.removeEventListener('change', debouncedModelSelectChange); | |
| 499 | 714 | // Add the debounced event listener |
| 500 | 715 | $(modelSelect).off('change').onaddEventListener('change', debouncedModelSelectChange); |
| 501 | 716 | } |
| 502 | 717 | |
| 503 | 718 | // DeepSpeed Listener |
| 504 | 719 | const deepspeedCheckbox = document.getElementById('deepspeed'); |
| 505 | 720 | if (deepspeedCheckbox) { |
| 506 | 721 | $(deepspeedCheckbox).off('change').onaddEventListener('change', async (event) => { |
| 507 | 722 | const deepSpeedValue = event.target.checked ? 'True' : 'False'; |
| 508 | 723 | // Set status to Processing |
| 509 | 724 | updateStatus('Processing'); |
| 510 | 725 | try { |
| 511 | 726 | const response = await fetch(`${this.settings.provider_endpoint}/api/deepspeed?new_deepspeed_value=${deepSpeedValue}`, { |
| 512 | 727 | method: 'POST', |
| 513 | 728 | }); |
| 514 | 729 | if (!response.ok) { |
| 515 | 730 | throw new Error(`HTTP Error: ${response.status}`); |
| 516 | 731 | } |
| 517 | 732 | const data = await response.json(); |
| 518 | 733 | console.log('"POST response data:'", data); // Debugging statement |
| 519 | 734 | // Set status to Ready if successful |
| 520 | 735 | updateStatus('Ready'); |
| 521 | 736 | } catch (error) { |
| 522 | 737 | console.error('"POST request error:'", error); // Debugging statement |
| 523 | 738 | // Set status to Error in case of failure |
| 524 | 739 | updateStatus('Error'); |
| 525 | 740 | } |
| 526 | 741 | }); |
| 527 | 742 | } |
| 528 | 743 | |
| 744 | + function lowvramdebounce(func, delay) { | |
| 745 | + let debounceTimer; | |
| 746 | + return function (...args) { | |
| 747 | + const context = this; | |
| 748 | + clearTimeout(debounceTimer); | |
| 749 | + debounceTimer = setTimeout(() => func.apply(context, args), delay); | |
| 750 | + }; | |
| 751 | + } | |
| 752 | + | |
| 529 | 753 | // Low VRAM Listener |
| 530 | 754 | const lowVramCheckbox = document.getElementById('low_vram'); |
| 531 | 755 | if (lowVramCheckbox) { |
| 532 | 756 | $(lowVramCheckbox).off('change').on('change',const handleLowVramChange = async (event) => { |
| 533 | 757 | const lowVramValue = event.target.checked ? 'True' : 'False'; |
| 534 | 758 | // Set status to Processing |
| 535 | 759 | updateStatus('Processing'); |
| 536 | 760 | try { |
| 537 | 761 | const response = await fetch(`${this.settings.provider_endpoint}/api/lowvramsetting?new_low_vram_value=${lowVramValue}`, { |
| 538 | 762 | method: 'POST', |
| 539 | 763 | }); |
| 540 | 764 | if (!response.ok) { |
| 541 | 765 | throw new Error(`HTTP Error: ${response.status}`); |
| 542 | 766 | } |
| 543 | 767 | const data = await response.json(); |
| 544 | 768 | console.log('"POST response data:'", data); // Debugging statement |
| 545 | 769 | // Set status to Ready if successful |
| 546 | 770 | updateStatus('Ready'); |
| 547 | 771 | } catch (error) { |
| 548 | 772 | console.error('"POST request error:'", error); // Debugging statement |
| 549 | 773 | // Set status to Error in case of failure |
| 550 | 774 | updateStatus('Error'); |
| 551 | 775 | } |
| 552 | 776 | }); |
| 777 | + | |
| 778 | + const debouncedHandleLowVramChange = lowvramdebounce(handleLowVramChange, 300); // Adjust delay as needed | |
| 779 | + | |
| 780 | + lowVramCheckbox.addEventListener('change', debouncedHandleLowVramChange); | |
| 553 | 781 | } |
| 554 | 782 | |
| 783 | + | |
| 555 | 784 | // Narrator Voice Dropdown Listener |
| 556 | 785 | const narratorVoiceSelect = document.getElementById('narrator_voice'); |
| 557 | 786 | if (narratorVoiceSelect) { |
| 558 | 787 | $(narratorVoiceSelect).off('change').onaddEventListener('change', (event) => { |
| 559 | 788 | this.settings.narrator_voice_gen = `${event.target.value}.wav`; |
| 560 | 789 | this.onSettingsChange(); // Save the settings after change |
| 561 | 790 | }); |
| 562 | 791 | } |
| 563 | 792 | |
| 564 | 793 | const textNotInsideSelect = document.getElementById('at_narrator_text_not_inside'); |
| 565 | 794 | if (textNotInsideSelect) { |
| 566 | 795 | $(textNotInsideSelect).off('change').onaddEventListener('change', (event) => { |
| 567 | 796 | this.settings.text_not_inside = event.target.value; |
| 568 | 797 | this.onSettingsChange(); // Save the settings after change |
| 569 | 798 | }); |
| @@ -571,39 +800,45 @@ class AllTalkTtsProvider { | ||
| 571 | 800 | |
| 572 | 801 | // AT Narrator Dropdown Listener |
| 573 | 802 | const atNarratorSelect = document.getElementById('at_narrator_enabled'); |
| 574 | 803 | const ttsPassAsterisksCheckbox = document.getElementById('tts_pass_asterisks'); // Access the checkbox from index.js |
| 575 | 804 | const ttsNarrateQuotedCheckbox = document.getElementById('tts_narrate_quoted'); // Access the checkbox from index.js |
| 576 | 805 | const ttsNarrateDialoguesCheckbox = document.getElementById('tts_narrate_dialogues'); // Access the checkbox from index.js |
| 577 | 806 | |
| 578 | 807 | if (atNarratorSelect && textNotInsideSelect && narratorVoiceSelect) { |
| 579 | 808 | $(atNarratorSelect).off('change').onaddEventListener('change', (event) => { |
| 580 | 809 | const isNarratorEnablednarratorOption = event.target.value === 'true'; |
| 581 | 810 | this.settings.narrator_enabled = isNarratorEnablednarratorOption; // Update the setting here |
| 582 | - textNotInsideSelect.disabled = !isNarratorEnabled; | |
| 811 | + | |
| 583 | - narratorVoiceSelect.disabled = !isNarratorEnabled; | |
| 812 | + // Check if narrator is disabled | |
| 584 | - | |
| 813 | + const isNarratorDisabled = narratorOption === 'false'; | |
| 585 | - // Sync the state with the checkbox in index.js | |
| 814 | + textNotInsideSelect.disabled = isNarratorDisabled; | |
| 586 | - if (isNarratorEnabled) { | |
| 815 | + narratorVoiceSelect.disabled = isNarratorDisabled; | |
| 816 | + | |
| 817 | + console.log(`Narrator option: ${narratorOption}`); | |
| 818 | + console.log(`textNotInsideSelect disabled: ${textNotInsideSelect.disabled}`); | |
| 819 | + console.log(`narratorVoiceSelect disabled: ${narratorVoiceSelect.disabled}`); | |
| 820 | + | |
| 821 | + if (narratorOption === 'true') { | |
| 587 | 822 | ttsPassAsterisksCheckbox.checked = false; |
| 588 | 823 | $('#tts_pass_asterisks').click(); // Simulate a click event |
| 589 | 824 | $('#tts_pass_asterisks').trigger('change'); |
| 590 | - } | |
| 591 | - if (!isNarratorEnabled) { | |
| 592 | - ttsPassAsterisksCheckbox.checked = true; | |
| 593 | - $('#tts_pass_asterisks').click(); // Simulate a click event | |
| 594 | - $('#tts_pass_asterisks').trigger('change'); | |
| 595 | - } | |
| 596 | - // Uncheck and set tts_narrate_quoted to false if narrator is enabled | |
| 597 | - if (isNarratorEnabled) { | |
| 598 | 825 | ttsNarrateQuotedCheckbox.checked = true; |
| 599 | 826 | ttsNarrateDialoguesCheckbox.checked = true; |
| 600 | - // Trigger click events instead of change events | |
| 601 | 827 | $('#tts_narrate_quoted').click(); |
| 602 | 828 | $('#tts_narrate_quoted').trigger('change'); |
| 603 | 829 | $('#tts_narrate_dialogues').click(); |
| 604 | 830 | $('#tts_narrate_dialogues').trigger('change'); |
| 831 | + } else if (narratorOption === 'silent') { | |
| 832 | + ttsPassAsterisksCheckbox.checked = false; | |
| 833 | + $('#tts_pass_asterisks').click(); | |
| 834 | + $('#tts_pass_asterisks').trigger('change'); | |
| 835 | + } else { | |
| 836 | + ttsPassAsterisksCheckbox.checked = true; | |
| 837 | + $('#tts_pass_asterisks').click(); | |
| 838 | + $('#tts_pass_asterisks').trigger('change'); | |
| 605 | 839 | } |
| 606 | - this.onSettingsChange(); // Save the settings after change | |
| 840 | + | |
| 841 | + this.onSettingsChange(); | |
| 607 | 842 | }); |
| 608 | 843 | } |
| 609 | 844 | |
| @@ -612,7 +847,7 @@ class AllTalkTtsProvider { | ||
| 612 | 847 | const atGenerationMethodSelect = document.getElementById('at_generation_method'); |
| 613 | 848 | const atNarratorEnabledSelect = document.getElementById('at_narrator_enabled'); |
| 614 | 849 | if (atGenerationMethodSelect) { |
| 615 | 850 | $(atGenerationMethodSelect).off('change').onaddEventListener('change', (event) => { |
| 616 | 851 | const selectedMethod = event.target.value; |
| 617 | 852 | |
| 618 | 853 | if (selectedMethod === 'streaming_enabled') { |
| @@ -633,7 +868,7 @@ class AllTalkTtsProvider { | ||
| 633 | 868 | // Listener for Language Dropdown |
| 634 | 869 | const languageSelect = document.getElementById('language_options'); |
| 635 | 870 | if (languageSelect) { |
| 636 | 871 | $(languageSelect).off('change').onaddEventListener('change', (event) => { |
| 637 | 872 | this.settings.language = event.target.value; |
| 638 | 873 | this.onSettingsChange(); // Save the settings after change |
| 639 | 874 | }); |
| @@ -642,7 +877,7 @@ class AllTalkTtsProvider { | ||
| 642 | 877 | // Listener for AllTalk Endpoint Input |
| 643 | 878 | const atServerInput = document.getElementById('at_server'); |
| 644 | 879 | if (atServerInput) { |
| 645 | 880 | $(atServerInput).off('input').onaddEventListener('input', (event) => { |
| 646 | 881 | this.settings.provider_endpoint = event.target.value; |
| 647 | 882 | this.onSettingsChange(); // Save the settings after change |
| 648 | 883 | }); |
| @@ -662,6 +897,10 @@ class AllTalkTtsProvider { | ||
| 662 | 897 | this.settings.at_generation_method = $('#at_generation_method').val(); |
| 663 | 898 | this.settings.narrator_enabled = $('#at_narrator_enabled').val(); |
| 664 | 899 | this.settings.at_narrator_text_not_inside = $('#at_narrator_text_not_inside').val(); |
| 900 | + this.settings.rvc_character_voice = $('#rvc_character_voice').val(); | |
| 901 | + this.settings.rvc_narrator_voice = $('#rvc_narrator_voice').val(); | |
| 902 | + this.settings.rvc_character_pitch = $('#rvc_character_pitch').val(); | |
| 903 | + this.settings.rvc_narrator_pitch = $('#rvc_narrator_pitch').val(); | |
| 665 | 904 | this.settings.narrator_voice_gen = $('#narrator_voice').val(); |
| 666 | 905 | // Save the updated settings |
| 667 | 906 | saveTtsProviderSettings(); |
| @@ -672,8 +911,16 @@ class AllTalkTtsProvider { | ||
| 672 | 911 | //#########################// |
| 673 | 912 | |
| 674 | 913 | async onRefreshClick() { |
| 675 | - await this.initEndpoint(); | |
| 914 | + try { | |
| 676 | - // Additional actions as needed | |
| 915 | + updateStatus('Processing'); // Set status to Processing while refreshing | |
| 916 | + await this.checkReady(); // Check if the TTS provider is ready | |
| 917 | + await this.loadSettings(this.settings); // Reload the settings | |
| 918 | + await this.checkReady(); // Check if the TTS provider is ready | |
| 919 | + updateStatus(this.ready ? 'Ready' : 'Offline'); // Update the status based on readiness | |
| 920 | + } catch (error) { | |
| 921 | + console.error('Error during refresh:', error); | |
| 922 | + updateStatus('Error'); // Set status to Error in case of failure | |
| 923 | + } | |
| 677 | 924 | } |
| 678 | 925 | |
| 679 | 926 | //##################// |
| @@ -684,33 +931,44 @@ class AllTalkTtsProvider { | ||
| 684 | 931 | try { |
| 685 | 932 | // Prepare data for POST request |
| 686 | 933 | const postData = new URLSearchParams(); |
| 687 | 934 | postData.append('"voice'", `${voiceName}.wav`); |
| 935 | + | |
| 936 | + // Add RVC parameters for V2 if applicable | |
| 937 | + if (this.settings.server_version === 'v2' && this.settings.rvc_character_voice !== 'Disabled') { | |
| 938 | + postData.append("rvccharacter_voice_gen", this.settings.rvc_character_voice); | |
| 939 | + postData.append("rvccharacter_pitch", this.settings.rvc_character_pitch || "0"); | |
| 940 | + } | |
| 941 | + | |
| 688 | 942 | // Making the POST request |
| 689 | 943 | const response = await fetch(`${this.settings.provider_endpoint}/api/previewvoice/`, { |
| 690 | 944 | method: '"POST'", |
| 691 | 945 | headers: { |
| 692 | 946 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 693 | 947 | }, |
| 694 | 948 | body: postData, |
| 695 | 949 | }); |
| 950 | + | |
| 696 | 951 | if (!response.ok) { |
| 697 | 952 | const errorText = await response.text(); |
| 698 | 953 | console.error('`[previewTtsVoice] Error Response Text:'`, errorText); |
| 699 | 954 | throw new Error(`HTTP ${response.status}: ${errorText}`); |
| 700 | 955 | } |
| 701 | - // Assuming the server returns a URL to the .wav file | |
| 956 | + | |
| 702 | 957 | const data = await response.json(); |
| 703 | 958 | if (data.output_file_url) { |
| 704 | - // Use an audio element to play the .wav file | |
| 959 | + // Handle V1/V2 URL differences | |
| 705 | - const audioElement = new Audio(data.output_file_url); | |
| 960 | + const fullUrl = this.settings.server_version === 'v1' | |
| 706 | - audioElement.play().catch(e => console.error('Error playing audio:', e)); | |
| 961 | + ? data.output_file_url | |
| 962 | + : `${this.settings.provider_endpoint}${data.output_file_url}`; | |
| 963 | + | |
| 964 | + const audioElement = new Audio(fullUrl); | |
| 965 | + audioElement.play().catch(e => console.error("Error playing audio:", e)); | |
| 707 | 966 | } else { |
| 708 | 967 | console.warn('"[previewTtsVoice] No output file URL received in the response'"); |
| 709 | 968 | throw new Error('"No output file URL received in the response'"); |
| 710 | 969 | } |
| 711 | - | |
| 712 | 970 | } catch (error) { |
| 713 | 971 | console.error('"[previewTtsVoice] Exception caught during preview generation:'", error); |
| 714 | 972 | throw error; |
| 715 | 973 | } |
| 716 | 974 | } |
| @@ -744,8 +1002,8 @@ class AllTalkTtsProvider { | ||
| 744 | 1002 | try { |
| 745 | 1003 | if (this.settings.at_generation_method === 'streaming_enabled') { |
| 746 | 1004 | // Construct the streaming URL |
| 747 | 1005 | const streamingUrl = `${this.settings.provider_endpoint}/api/tts-generate-streaming?text=${encodeURIComponent(inputText)}&voice=${encodeURIComponent(voiceId)}.wav&language=${encodeURIComponent(this.settings.language)}&output_file=stream_output.wav`; |
| 748 | 1006 | console.log('"Streaming URL:'", streamingUrl); |
| 749 | 1007 | |
| 750 | 1008 | // Return the streaming URL directly |
| 751 | 1009 | return streamingUrl; |
| @@ -759,7 +1017,7 @@ class AllTalkTtsProvider { | ||
| 759 | 1017 | return audioResponse; // Return the fetch response directly |
| 760 | 1018 | } |
| 761 | 1019 | } catch (error) { |
| 762 | 1020 | console.error('"Error in generateTts:'", error); |
| 763 | 1021 | throw error; |
| 764 | 1022 | } |
| 765 | 1023 | } |
| @@ -770,20 +1028,31 @@ class AllTalkTtsProvider { | ||
| 770 | 1028 | //####################// |
| 771 | 1029 | |
| 772 | 1030 | async fetchTtsGeneration(inputText, voiceId) { |
| 773 | - // Prepare the request payload | |
| 774 | 1031 | const requestBody = new URLSearchParams({ |
| 775 | 1032 | 'text_input': inputText, |
| 776 | 1033 | 'text_filtering': '"standard'", |
| 777 | 1034 | 'character_voice_gen': voiceId + '.wav', |
| 778 | 1035 | 'narrator_enabled': this.settings.narrator_enabled, |
| 779 | 1036 | 'narrator_voice_gen': this.settings.narrator_voice_gen + '.wav', |
| 780 | 1037 | 'text_not_inside': this.settings.at_narrator_text_not_inside, |
| 781 | 1038 | 'language': this.settings.language, |
| 782 | 1039 | 'output_file_name': '"st_output'", |
| 783 | 1040 | 'output_file_timestamp': '"true'", |
| 784 | 1041 | 'autoplay': '"false'", |
| 785 | 1042 | 'autoplay_volume': '"0.8'," |
| 786 | 1043 | }).toString(); |
| 1044 | + | |
| 1045 | + // Add RVC parameters only for V2 | |
| 1046 | + if (this.settings.server_version === 'v2') { | |
| 1047 | + if (this.settings.rvc_character_voice !== 'Disabled') { | |
| 1048 | + requestBody.append('rvccharacter_voice_gen', this.settings.rvc_character_voice); | |
| 1049 | + requestBody.append('rvccharacter_pitch', this.settings.rvc_character_pitch || "0"); | |
| 1050 | + } | |
| 1051 | + if (this.settings.rvc_narrator_voice !== 'Disabled') { | |
| 1052 | + requestBody.append('rvcnarrator_voice_gen', this.settings.rvc_narrator_voice); | |
| 1053 | + requestBody.append('rvcnarrator_pitch', this.settings.rvc_narrator_pitch || "0"); | |
| 1054 | + } | |
| 1055 | + } | |
| 787 | 1056 | |
| 788 | 1057 | try { |
| 789 | 1058 | const response = await doExtrasFetch( |
| @@ -794,22 +1063,26 @@ class AllTalkTtsProvider { | ||
| 794 | 1063 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 795 | 1064 | 'Cache-Control': 'no-cache', |
| 796 | 1065 | }, |
| 797 | 1066 | body: requestBody, |
| 798 | 1067 | }, |
| 799 | 1068 | ); |
| 800 | 1069 | |
| 801 | 1070 | if (!response.ok) { |
| 802 | 1071 | const errorText = await response.text(); |
| 803 | 1072 | console.error('`[fetchTtsGeneration] Error Response Text:'`, errorText); |
| 804 | - // toastr.error(response.statusText, 'TTS Generation Failed'); | |
| 805 | 1073 | throw new Error(`HTTP ${response.status}: ${errorText}`); |
| 806 | 1074 | } |
| 807 | 1075 | const data = await response.json(); |
| 808 | - const outputUrl = data.output_file_url; | |
| 1076 | + | |
| 809 | - return outputUrl; // Return only the output_file_url | |
| 1077 | + // Handle V1/V2 URL differences | |
| 1078 | + const outputUrl = this.settings.server_version === 'v1' | |
| 1079 | + ? data.output_file_url // V1 returns full URL | |
| 1080 | + : `${this.settings.provider_endpoint}${data.output_file_url}`; // V2 returns relative path | |
| 1081 | + | |
| 1082 | + return outputUrl; | |
| 810 | 1083 | } catch (error) { |
| 811 | 1084 | console.error('"[fetchTtsGeneration] Exception caught:'", error); |
| 812 | - throw error; // Rethrow the error for further handling | |
| 1085 | + throw error; | |
| 813 | 1086 | } |
| 814 | 1087 | } |
| 815 | 1088 | } |