You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

泰卢固语单词发音网站故障:代码无报错但无法发音

泰卢固语字母发音网站修复方案

核心问题分析

你的代码中存在一个关键错误:将语音语言代码设置为了印地语的hi-IN,而非泰卢固语的te-IN,这是导致无法正确发音泰卢固语内容的主要原因。此外,还可以补充一些优化点提升功能稳定性。

修复后的完整代码

HTML 代码

<h1>泰卢固语字母发音</h1>
<input type="text" id="wordInput" placeholder="输入泰卢固语字母/单词">
<button id="pronounceButton">发音</button>

JavaScript 代码

// 检查浏览器是否支持Web Speech API
if ('speechSynthesis' in window) {
  const wordInput = document.getElementById('wordInput');
  const pronounceButton = document.getElementById('pronounceButton');

  function pronounceWord() {
    const teluguWord = wordInput.value.trim();

    if (teluguWord !== '') {
      // 清空之前的语音队列,避免任务堆积导致无响应
      window.speechSynthesis.cancel();
      
      const speech = new SpeechSynthesisUtterance();
      speech.lang = 'te-IN'; // 修正为泰卢固语标准语言代码
      speech.text = teluguWord;
      // 可选:自定义语音参数
      speech.volume = 1; // 音量(0-1)
      speech.rate = 1;   // 语速(0.1-10)
      speech.pitch = 1;  // 音调(0-2)
      
      window.speechSynthesis.speak(speech);
    } else {
      alert('请输入泰卢固语字母或单词。');
    }
  }

  // 按钮点击触发发音
  pronounceButton.addEventListener('click', pronounceWord);
  // 回车键触发发音,优化输入体验
  wordInput.addEventListener('keypress', (e) => {
    if (e.key === 'Enter') {
      pronounceWord();
    }
  });
} else {
  alert("当前浏览器不支持语音合成功能,请更换主流浏览器重试。");
}

额外注意事项

  • 浏览器语音包支持:部分浏览器需要手动安装泰卢固语语音合成包(例如Chrome可在「设置-语言-添加语言」中找到泰卢固语并安装对应的语音引擎)。
  • 输入验证:如果需要严格限制输入为泰卢固语字符,可以添加正则表达式验证:
    const isTelugu = /[\u0C00-\u0C7F]/.test(teluguWord);
    if (!isTelugu) {
      alert('请输入有效的泰卢固语内容。');
      return;
    }
    

内容的提问来源于stack exchange,提问作者ammu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 14:57:30