我想创建一个可以发音泰卢固语字母的网站。即使代码没有显示任何错误,它也不会发音给定的字母。
我尝试了以下代码,但没有成功
// Check if the browser supports the Web Speech API
if ('speechSynthesis' in window) {
const wordInput = document.getElementById('wordInput');
const pronounceButton = document.getElementById('pronounceButton');
// Create a function to pronounce the entered Telugu word
function pronounceWord() {
const teluguWord = wordInput.value.trim();
if (teluguWord !== '') {
let speech = new SpeechSynthesisUtterance();
speech.lang = 'hi-IN'; // Set the language to Telugu (te-IN)
speech.text = teluguWord;
window.speechSynthesis.speak(speech);
} else {
alert('Please enter a Telugu word.');
}
}
// Add an event listener to the button
pronounceButton.addEventListener('click', pronounceWord);
} else {
alert("Speech synthesis not supported in this browser.");
}
<h1>Pronounce Telugu Words</h1>
<input type="text" id="wordInput" placeholder="Enter a Telugu word">
<button id="pronounceButton">Pronounce</button>
你的代码很好,我检查并运行了该文件,虽然当它发音时听起来像英语,但代码正在运行。可能是浏览器问题或您的扬声器已关闭。