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

在Safari/iOS 18中使用speechSynthesis调用日语语音的问题

iOS 18.0 模拟器 SpeechSynthesis 日语语音无法加载问题

问题概述

在iOS 18.0的iPhone 16模拟器中,即便已下载日语语音,speechSynthesis.getVoices()返回的列表里始终找不到日语语音;仅设置utterance.lang = 'ja'时,系统会用英语语音朗读且无法处理日语字符,也无法触发日语语音的加载流程。

已尝试的操作:

  • 将日语设为系统首选语言
  • 在辅助功能「朗读所选内容」中切换日语语音
  • 设置HTML的lang属性为ja

最小复现代码

const voices = speechSynthesis.getVoices();
const voice = voices.filter((v) => v.lang.startsWith('ja'))[0];
const utterance = new SpeechSynthesisUtterance('こんにちは');
utterance.voice = voice;
utterance.lang = 'ja';
speechSynthesis.speak(utterance);

解决方案建议

1. 监听voiceschanged事件确保语音列表加载完成

speechSynthesis.getVoices()的返回结果是异步加载的,页面初始化时直接调用可能无法获取完整的语音列表。需要监听voiceschanged事件,在列表更新后再筛选目标语音:

function speakJapanese() {
  const voices = speechSynthesis.getVoices();
  const jaVoice = voices.find(v => v.lang.startsWith('ja'));
  const utterance = new SpeechSynthesisUtterance('こんにちは');
  
  if (jaVoice) {
    utterance.voice = jaVoice;
  }
  utterance.lang = 'ja';
  speechSynthesis.speak(utterance);
}

// 首次尝试获取语音并朗读
speakJapanese();
// 监听语音列表更新事件
speechSynthesis.addEventListener('voiceschanged', speakJapanese);

2. 验证模拟器语音下载状态

iOS模拟器的语音下载可能存在延迟或未真正完成的情况:

  • 进入「设置」→「辅助功能」→「朗读内容」→「语音」,确认日语语音显示为「已下载」
  • 尝试删除日语语音后重新下载,重启模拟器再测试

3. 遵循iOS交互触发限制

iOS平台的SpeechSynthesis受浏览器安全限制,语音合成操作需由用户交互触发:

  • 将语音合成代码放在按钮点击等用户主动触发的事件回调中,而非页面初始化时自动执行
  • 可尝试先创建一个空的utterance并调用speak(),再重新获取语音列表,可能触发系统加载已下载的语音

4. 调整系统语言优先级

在「设置」→「通用」→「语言与地区」中,将日语移至语言列表顶部,部分系统功能会优先使用列表顶部的语言,可能影响语音合成的语音匹配逻辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 09:45:54