örneğin my love ifadesini chrome da may lav şeklinde olması gerektiği gibi ingiliz aksanıyla telaffuz ederken safari ve operada me ye looove diyerek ediyor. Bu sorunu nasıl çözeriz ücretli ücretsiz destek alınır. Kod yapısı aşağıdadır
<script>
const data = <?php echo json_encode($kelimeler); ?>;
let current = 0;
const phraseEl = document.getElementById("phrase");
const meanEl = document.getElementById("mean");
const sentenceEl = document.getElementById("sentence");
const progressBar = document.getElementById("progressBar");
function renderCard() {
const w = data[current];
phraseEl.textContent = w.phrase;
meanEl.textContent = w.mean;
sentenceEl.textContent = w.sampleSentence;
progressBar.style.width = ((current + 1) / data.length * 100) + "%";
animateCard();
}
function nextCard(){ if(current < data.length-1){ current++; renderCard(); } }
function prevCard(){ if(current > 0){ current--; renderCard(); } }
function animateCard(){
const card = document.getElementById("flashcard");
card.style.opacity = 0; setTimeout(()=>{ card.style.opacity = 1; }, 200);
}
// ---------- TTS: güvenli ses yükleme + kesin İngilizce seçimi ----------
const EN_PRIORITY_NAMES = [
// Chromium (Chrome/Opera/Edge)
"Google US English","Google UK English Male","Google UK English Female",
// iOS/macOS Safari
"Samantha","Alex","Victoria","Moira","Daniel","Karen","Tessa","Fiona"
];
// voices’ın gerçekten yüklendiğinden emin olmak için promisify
const voicesReady = new Promise(resolve => {
function done(){
const v = speechSynthesis.getVoices();
if (v && v.length) resolve(v);
}
speechSynthesis.onvoiceschanged = done;
// bazı tarayıcılarda onvoiceschanged hiç tetiklenmiyor:
const tryPoll = () => {
const v = speechSynthesis.getVoices();
if (v && v.length) resolve(v);
else setTimeout(tryPoll, 150);
};
tryPoll();
});
function pickEnglishVoice(voices){
// 1) İsim önceliği
for (const name of EN_PRIORITY_NAMES){
const hit = voices.find(v => v.name === name);
if (hit) return hit;
}
// 2) Dil eşleşmesi (US > UK > diğer EN)
const byUS = voices.find(v => /^en[-_]?us/i.test(v.lang));
if (byUS) return byUS;
const byGB = voices.find(v => /^en[-_]?gb/i.test(v.lang));
if (byGB) return byGB;
const anyEN = voices.find(v => /^en/i.test(v.lang));
if (anyEN) return anyEN;
return null;
}
async function speak(){
// bazı tarayıcılar önceki konuşmayı kesmeden dili değiştirmiyor
speechSynthesis.cancel();
const voices = await voicesReady;
const enVoice = pickEnglishVoice(voices);
const msg = new SpeechSynthesisUtterance(data[current].phrase);
msg.rate = 0.95; // daha doğal hız
msg.pitch = 1.0;
msg.volume = 1.0;
if (enVoice){
msg.voice = enVoice;
msg.lang = enVoice.lang || 'en-US'; // Safari’de lang boş olabiliyor
} else {
// son çare: sadece lang ver (bazı cihazlarda TR’ye düşebilir)
msg.lang = 'en-US';
// kullanıcıya yönlendirme (isteğe bağlı)
console.warn('İngilizce ses bulunamadı. Cihazın TTS ayarlarından English (US/UK) ses paketini kur.');
// dil kilitlemesine yardımcı olabiliyor: kısa “.” ile başlatıp hemen iptal et
const probe = new SpeechSynthesisUtterance(".");
probe.lang = 'en-US';
speechSynthesis.speak(probe);
speechSynthesis.cancel();
}
// Bazı iOS sürümlerinde ilk speak boşa düşebiliyor; kısa gecikme yardım eder
setTimeout(() => speechSynthesis.speak(msg), 50);
}
window.onload = renderCard;
</script>