Fix ESLint errors

bce6f3eef0d284a48e029ac376da9dd6a9d07934

Boof2015 <75185879+Boof2015@users.noreply.github.com>

Signed
1 files changed, +45 -45Ignore whitespace
public/scripts/extensions/tts/chatterbox.js+45 -45
@@ -27,7 +27,7 @@ class ChatterboxTtsProvider {
2727 voiceMap: this.settings.voiceMap || {},
2828 };
2929 }
30-
30+
3131 ready = false;
3232 voices = [];
3333 separator = '. ';
@@ -134,7 +134,7 @@ class ChatterboxTtsProvider {
134134 </select>
135135 </div>`;
136136
137137 html += `'</div>`'; // End params section
138138
139139 // Footer with links
140140 html += `<div class="chatterbox-footer">
@@ -142,7 +142,7 @@ class ChatterboxTtsProvider {
142142 <a href="https://github.com/devnen/Chatterbox-TTS-Server" target="_blank">Documentation</a>
143143 </div>`;
144144
145145 html += `'</div>`'; // End container
146146
147147 // Add CSS styles
148148 html += `<style>
@@ -224,19 +224,19 @@ class ChatterboxTtsProvider {
224224 this.updateUIFromSettings();
225225
226226 console.debug('ChatterboxTTS: Settings loaded');
227-
227+
228228 try {
229229 // Check if TTS provider is ready
230230 await this.checkReady();
231-
231+
232232 if (this.ready) {
233233 // Fetch all voice types for the voice map
234234 await this.fetchTtsVoiceObjects();
235235 this.updateStatus('Ready');
236236 }
237-
237+
238238 this.setupEventListeners();
239-
239+
240240 } catch (error) {
241241 console.error('Error loading Chatterbox settings:', error);
242242 this.updateStatus('Offline');
@@ -274,13 +274,13 @@ class ChatterboxTtsProvider {
274274 async checkReady() {
275275 try {
276276 const response = await fetch(`${this.settings.provider_endpoint}/api/ui/initial-data`);
277-
277+
278278 if (!response.ok) {
279279 throw new Error(`HTTP Error Response: ${response.status} ${response.statusText}`);
280280 }
281-
281+
282282 const data = await response.json();
283-
283+
284284 // Check if we got valid data
285285 if (data) {
286286 this.ready = true;
@@ -306,15 +306,15 @@ class ChatterboxTtsProvider {
306306 if (!predefinedResponse.ok) {
307307 throw new Error(`HTTP ${predefinedResponse.status}: ${predefinedResponse.statusText}`);
308308 }
309-
309+
310310 const predefinedData = await predefinedResponse.json();
311-
311+
312312 // Transform predefined voices
313313 const predefinedVoices = predefinedData.map(voice => ({
314314 name: voice.display_name,
315315 voice_id: voice.voice_id,
316316 preview_url: null,
317317 lang: voice.language || 'en',
318318 }));
319319
320320 // Always try to fetch reference voices
@@ -327,16 +327,16 @@ class ChatterboxTtsProvider {
327327 name: `[Clone] ${filename}`,
328328 voice_id: `ref_${filename}`,
329329 preview_url: null,
330330 lang: 'en',
331331 }));
332332 }
333333 } catch (error) {
334334 console.warn('Failed to fetch reference voices:', error);
335335 }
336-
336+
337337 // Combine all voices
338338 this.voices = [...predefinedVoices, ...referenceVoices];
339-
339+
340340 console.log(`Loaded ${this.voices.length} voices (${predefinedVoices.length} predefined, ${referenceVoices.length} reference)`);
341341 return this.voices;
342342 } catch (error) {
@@ -439,7 +439,7 @@ class ChatterboxTtsProvider {
439439 try {
440440 this.updateStatus('Processing');
441441 await this.checkReady();
442-
442+
443443 if (this.ready) {
444444 await this.fetchTtsVoiceObjects();
445445 this.updateStatus('Ready');
@@ -459,18 +459,18 @@ class ChatterboxTtsProvider {
459459 async previewTtsVoice(voiceId) {
460460 try {
461461 this.updateStatus('Processing');
462-
462+
463463 const previewText = "'Hello! This is a preview of the selected voice."';
464-
464+
465465 // Determine if this is a reference voice
466466 let isReferenceVoice = false;
467467 let actualVoiceId = voiceId;
468-
468+
469469 if (voiceId && voiceId.startsWith('ref_')) {
470470 isReferenceVoice = true;
471471 actualVoiceId = voiceId.substring(4); // Remove 'ref_' prefix
472472 }
473-
473+
474474 // Generate preview using the main TTS endpoint
475475 const requestBody = {
476476 text: previewText,
@@ -482,7 +482,7 @@ class ChatterboxTtsProvider {
482482 speed_factor: this.settings.speed_factor,
483483 language: this.settings.language,
484484 split_text: false, // Don't split for preview
485485 output_format: this.settings.output_format,
486486 };
487487
488488 // Add voice-specific parameters
@@ -495,9 +495,9 @@ class ChatterboxTtsProvider {
495495 const response = await fetch(`${this.settings.provider_endpoint}/tts`, {
496496 method: 'POST',
497497 headers: {
498498 'Content-Type': 'application/json',
499499 },
500500 body: JSON.stringify(requestBody),
501501 });
502502
503503 if (!response.ok) {
@@ -507,15 +507,15 @@ class ChatterboxTtsProvider {
507507 // Get the audio blob and play it
508508 const audioBlob = await response.blob();
509509 const audioUrl = URL.createObjectURL(audioBlob);
510-
510+
511511 const audio = new Audio(audioUrl);
512512 audio.addEventListener('ended', () => {
513513 URL.revokeObjectURL(audioUrl);
514514 this.updateStatus('Ready');
515515 });
516-
516+
517517 await audio.play();
518-
518+
519519 } catch (error) {
520520 console.error('Error previewing voice:', error);
521521 this.updateStatus('Ready');
@@ -532,14 +532,14 @@ class ChatterboxTtsProvider {
532532 if (this.voices.length === 0) {
533533 await this.fetchTtsVoiceObjects();
534534 }
535-
535+
536536 // Find the voice object by name or voice_id
537537 let match = this.voices.find(voice =>
538538 voice.name === voiceName ||
539539 voice.voice_id === voiceName ||
540540 voice.display_name === voiceName,
541541 );
542-
542+
543543 if (!match) {
544544 console.warn(`Voice not found: ${voiceName}`);
545545 // Check if it's a reference voice that wasn't in the list
@@ -549,7 +549,7 @@ class ChatterboxTtsProvider {
549549 name: `[Clone] ${filename}`,
550550 voice_id: voiceName,
551551 preview_url: null,
552552 lang: 'en',
553553 };
554554 }
555555 // Return a default voice object
@@ -557,10 +557,10 @@ class ChatterboxTtsProvider {
557557 name: voiceName || 'Default',
558558 voice_id: voiceName || this.settings.predefined_voice || 'S1',
559559 preview_url: null,
560560 lang: 'en',
561561 };
562562 }
563-
563+
564564 return match;
565565 }
566566
@@ -571,16 +571,16 @@ class ChatterboxTtsProvider {
571571 async generateTts(inputText, voiceId) {
572572 try {
573573 this.updateStatus('Processing');
574-
574+
575575 // Determine if this is a reference voice
576576 let isReferenceVoice = false;
577577 let actualVoiceId = voiceId;
578-
578+
579579 if (voiceId && voiceId.startsWith('ref_')) {
580580 isReferenceVoice = true;
581581 actualVoiceId = voiceId.substring(4); // Remove 'ref_' prefix
582582 }
583-
583+
584584 // Prepare the request body
585585 const requestBody = {
586586 text: inputText,
@@ -593,7 +593,7 @@ class ChatterboxTtsProvider {
593593 language: this.settings.language,
594594 split_text: this.settings.split_text,
595595 chunk_size: this.settings.chunk_size,
596596 output_format: this.settings.output_format,
597597 };
598598
599599 // Add voice-specific parameters
@@ -609,9 +609,9 @@ class ChatterboxTtsProvider {
609609 method: 'POST',
610610 headers: {
611611 'Content-Type': 'application/json',
612612 'Cache-Control': 'no-cache',
613613 },
614614 body: JSON.stringify(requestBody),
615615 });
616616
617617 if (!response.ok) {
@@ -621,10 +621,10 @@ class ChatterboxTtsProvider {
621621 }
622622
623623 this.updateStatus('Ready');
624-
624+
625625 // Return the response directly - SillyTavern expects a Response object
626626 return response;
627-
627+
628628 } catch (error) {
629629 console.error('Error in generateTts:', error);
630630 this.updateStatus('Ready');
@@ -643,4 +643,4 @@ class ChatterboxTtsProvider {
643643 statusElement.className = status.toLowerCase();
644644 }
645645 }
646-}
646 \ No newline at end of file
646+}