Skip to content

Commit 9e5e1e2

Browse files
committed
fix(speech): set TTS lang for non-English, reload voices after language load, update STT lang dynamically
1 parent e32ed76 commit 9e5e1e2

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

interview/proctored-room.html

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,13 @@ <h1><span class="brand-simp">Simpatico</span><span class="brand-hr">HR</span></h
25802580
if (state.meta.interview.interview_language) {
25812581
state.interviewLanguage = state.meta.interview.interview_language;
25822582
console.log('[Lang] Interview language set to:', state.interviewLanguage);
2583+
// Re-load voices to match the interview language
2584+
loadVoices();
2585+
// Update STT recognition language if already initialized
2586+
if (state.voice.recognition) {
2587+
state.voice.recognition.lang = state.interviewLanguage;
2588+
console.log('[STT] Updated recognition lang to:', state.interviewLanguage);
2589+
}
25832590
}
25842591
}
25852592
} catch (e) {
@@ -2684,15 +2691,36 @@ <h1><span class="brand-simp">Simpatico</span><span class="brand-hr">HR</span></h
26842691
function loadVoices() {
26852692
const voices = state.voice.synth.getVoices();
26862693
const lang = state.interviewLanguage || 'en-IN';
2687-
const langBase = lang.split('-')[0]; // e.g. 'hi', 'ta', 'en'
2694+
const langBase = lang.split('-')[0]; // e.g. 'hi', 'ta', 'ml', 'en'
2695+
2696+
console.log(`[Voice] Looking for voice: lang=${lang}, base=${langBase}, available=${voices.length} voices`);
26882697

26892698
// For non-English languages, find a matching voice first
26902699
if (langBase !== 'en') {
2700+
// Log all matching voices for debugging
2701+
const matchingVoices = voices.filter(v => v.lang.startsWith(langBase));
2702+
console.log(`[Voice] Found ${matchingVoices.length} voices for '${langBase}':`, matchingVoices.map(v => `${v.name} (${v.lang})`));
2703+
2704+
// Prefer Google voices (usually higher quality for Indian languages)
2705+
const googleMatch = matchingVoices.find(v => v.name.toLowerCase().includes('google'));
2706+
if (googleMatch) {
2707+
state.voice.preferredVoice = googleMatch;
2708+
console.log(`[Voice] ✓ Selected Google voice: ${googleMatch.name} (${googleMatch.lang})`);
2709+
return;
2710+
}
26912711
const exactMatch = voices.find(v => v.lang === lang);
2692-
if (exactMatch) { state.voice.preferredVoice = exactMatch; return; }
2712+
if (exactMatch) {
2713+
state.voice.preferredVoice = exactMatch;
2714+
console.log(`[Voice] ✓ Selected exact match: ${exactMatch.name} (${exactMatch.lang})`);
2715+
return;
2716+
}
26932717
const baseMatch = voices.find(v => v.lang.startsWith(langBase));
2694-
if (baseMatch) { state.voice.preferredVoice = baseMatch; return; }
2695-
console.warn(`[Voice] No voice found for ${lang}, falling back to English`);
2718+
if (baseMatch) {
2719+
state.voice.preferredVoice = baseMatch;
2720+
console.log(`[Voice] ✓ Selected base match: ${baseMatch.name} (${baseMatch.lang})`);
2721+
return;
2722+
}
2723+
console.warn(`[Voice] ⚠️ No voice found for ${lang}! Malayalam/other Indic TTS requires Chrome. Falling back to English.`);
26962724
}
26972725

26982726
// English preferred voices
@@ -3005,6 +3033,8 @@ <h1><span class="brand-simp">Simpatico</span><span class="brand-hr">HR</span></h
30053033
const u = new SpeechSynthesisUtterance(chunks[idx]);
30063034
state.voice.keepAlive.push(u);
30073035

3036+
// Set the language on the utterance so the browser picks the correct voice
3037+
u.lang = state.interviewLanguage || 'en-IN';
30083038
if (state.voice.preferredVoice) u.voice = state.voice.preferredVoice;
30093039
u.rate = 0.92;
30103040
u.pitch = 1.0;

0 commit comments

Comments
 (0)