cleaned all redundant comments

d7cc70256aaec88fd6a0f0499656aebf31756661

YunZLu <130174259+YunZLu@users.noreply.github.com>

Signed
1 files changed, +5 -32Showing whitespace changes
public/scripts/extensions/tts/system.js+5 -32
@@ -172,83 +172,66 @@ class SystemTtsProvider {
172172 //#################//
173173 fetchTtsVoiceObjects() {
174174 if (!('speechSynthesis' in window)) {
175- // Browser doesn't support speech synthesis
176175 return Promise.resolve([]);
177176 }
178177
179178 return new Promise((resolve) => {
180- // Use a minimal timeout to allow the voice list to potentially populate
181179 setTimeout(() => {
182180 let voices = speechSynthesis.getVoices();
183181
184182 if (voices.length === 0) {
185- // If no voices returned (e.g., Edge on first load), provide a default option
183+ // Edge compat: Provide default when voices empty
186184 console.warn('SystemTTS: getVoices() returned empty list. Providing browser default option.');
187185 const defaultVoice = {
188186 name: SystemTtsProvider.BROWSER_DEFAULT_VOICE_NAME,
189187 voice_id: SystemTtsProvider.BROWSER_DEFAULT_VOICE_ID,
190188 preview_url: false,
191- // Try to guess the browser's default language
192189 lang: navigator.language || 'en-US',
193190 };
194191 resolve([defaultVoice]);
195192 } else {
196- // If voices are available, map them as before
197193 const mappedVoices = voices
198194 .sort((a, b) => a.lang.localeCompare(b.lang) || a.name.localeCompare(b.name))
199195 .map(x => ({ name: x.name, voice_id: x.voiceURI, preview_url: false, lang: x.lang }));
200196 resolve(mappedVoices);
201197 }
202- }, 50); // Increased timeout slightly just in case it helps voice population on some browsers
198+ }, 50);
203199 });
204200 }
205201
206-
207202 previewTtsVoice(voiceId) {
208203 if (!('speechSynthesis' in window)) {
209204 throw new Error('Speech synthesis API is not supported'); // Keep Error type for consistency
210205 }
211206
212207 let voice = null;
213- // Check if the requested voice is NOT the browser default
214208 if (voiceId !== SystemTtsProvider.BROWSER_DEFAULT_VOICE_ID) {
215209 const voices = speechSynthesis.getVoices();
216- // Try to find the actual voice
217210 voice = voices.find(x => x.voiceURI === voiceId);
218211
219212 if (!voice && voices.length > 0) {
220- // If voices are loaded but the specific ID wasn't found, log a warning
221213 console.warn(`SystemTTS Preview: Voice ID "${voiceId}" not found among available voices. Using browser default.`);
222- // Fallback to default (voice remains null)
223214 } else if (!voice && voices.length === 0) {
224- // If no voices are loaded at all, we expect to use default
225215 console.warn('SystemTTS Preview: Voice list is empty. Using browser default.');
226- // Fallback to default (voice remains null)
227216 }
228217 } else {
229218 console.log('SystemTTS Preview: Using browser default voice as requested.');
230- // Use default (voice remains null)
231219 }
232220
233221 speechSynthesis.cancel(); // Stop any previous speech
234- // Use the language from the found voice if available, otherwise default to 'en-US' or browser lang for the preview text
235222 const langForPreview = voice ? voice.lang : (navigator.language || 'en-US');
236223 const text = getPreviewString(langForPreview);
237224 const utterance = new SpeechSynthesisUtterance(text);
238225
239- // Only set the voice if we found a specific one and it wasn't the default request
240226 if (voice) {
241227 utterance.voice = voice;
242228 }
243- // Otherwise, utterance.voice remains null/undefined, causing the browser to use its default
244229
245230 utterance.rate = this.settings.rate || 1;
246231 utterance.pitch = this.settings.pitch || 1;
247232
248- // Add error handling for the speech itself
249233 utterance.onerror = (event) => {
250234 console.error(`SystemTTS Preview Error: ${event.error}`, event);
251- // Potentially notify the user here
252235 };
253236
254237 speechSynthesis.speak(utterance);
@@ -256,11 +239,9 @@ class SystemTtsProvider {
256239
257240 async getVoice(voiceName) {
258241 if (!('speechSynthesis' in window)) {
259- // Return a predictable null-like structure if API not supported
260242 return { voice_id: null, name: 'API Not Supported' };
261243 }
262244
263- // Check if the requested name is the browser default placeholder
264245 if (voiceName === SystemTtsProvider.BROWSER_DEFAULT_VOICE_NAME) {
265246 return {
266247 voice_id: SystemTtsProvider.BROWSER_DEFAULT_VOICE_ID,
@@ -268,16 +249,10 @@ class SystemTtsProvider {
268249 };
269250 }
270251
271- // Attempt to get voices, might be async
272- // Note: This relies on voices potentially being populated by now.
273- // A more robust approach might involve re-calling fetchTtsVoiceObjects if needed,
274- // but sticking to minimal changes based on original code structure.
275252 const voices = speechSynthesis.getVoices();
276253
277254 if (voices.length === 0) {
278- // If voices are still empty, we can't find any specific name
255+ console.warn('SystemTTS: Empty voice list, using default fallback');
279- console.warn(`SystemTTS getVoice: Voice list empty, cannot find "${voiceName}". Falling back to browser default ID.`);
280- // Return the default placeholder as a fallback in this edge case
281256 return {
282257 voice_id: SystemTtsProvider.BROWSER_DEFAULT_VOICE_ID,
283258 name: SystemTtsProvider.BROWSER_DEFAULT_VOICE_NAME,
@@ -287,7 +262,6 @@ class SystemTtsProvider {
287262 const match = voices.find(x => x.name == voiceName);
288263
289264 if (!match) {
290- // If voices are loaded but name not found, throw error as before
291265 throw new Error(`SystemTTS getVoice: TTS Voice name "${voiceName}" not found`);
292266 }
293267
@@ -313,7 +287,6 @@ class SystemTtsProvider {
313287 speechUtteranceChunker(utterance, {
314288 chunkLength: 200,
315289 }, function () {
316- //some code to execute when done
317290 resolve(silence);
318291 console.log('System TTS done');
319292 });