iOS Safari SpeechSynthesisUtterance 无法设置语言

iOS Safari SpeechSynthesisUtterance can not set language

我的 SpeechSynthesisUtterance 以我的母语(英语)工作,但我需要将语言设置为意大利语才能正确发音。

代码在 Mac Safari 中工作正常,但在 iOS Safari 中发音是英语而不是意大利语。

一个简单的测试是意大利语:“Ho i soldi”,“h”在意大利语中不发音。

<!DOCTYPE html><html lang='en' class=''>

<head><meta charset='UTF-8'></head>
<body>

<button id="Ho una prenotazione." onclick=speak(id)>Ho una prenotazione.</button>
I have a reservation

<script >
    function speak(text) {
        var msg    = new SpeechSynthesisUtterance(text);
        msg.lang = 'it-IT';
        window.speechSynthesis.speak(msg);
    }
</script>


</body></html>

这里是对上述代码的测试example

我已经下载了意大利语“Luca”并将其设为默认 Settings:General:Accessibility:Speech:Voices:Italian;Luca

注:

我已于 2018 年 7 月 26 日 post 对 Apple Safari 和 Web Development Forum 进行了查询,结果迄今为止没有回复:(422 次浏览,0 次回复)。

我还于 2018 年 8 月 16 日提交了 Apple 开发者技术支持 (DTS) 请求,该请求被拒绝并建议 post 到 Web Development Forum

虽然这可能被认为是题外话,但请考虑我已经尝试调试并向 Apple 请求帮助,但已被忽略和拒绝。

更新日期:

因此似乎是一个 iOS 测试版问题,甚至 Chrome 和 Firefox 应用程序也有英文发音。我已提交关于此问题的 Beta 错误报告。

我不得不在评论中对 post 进行少量的回复,所以我将 post 它作为一个答案。 我看到你是 运行 iphone 6s,但我在我的 iphone X 和我的 Mac 上用不同的浏览器用英语和意大利语试过了。

There is a possibility that the problem persists within your phone or os because it seems to work perfect on my devices, have you tried any other devices than your iphone 6s?

这个问题似乎纯粹是为了测试版。对于 iPhone 6、7 和 8 Plus,相同的 HTML 在 iOS 11.4.1 上工作正常。但是,通过将语言更改为西班牙语,它可以完美运行。

<html lang='es' class=''>

当然,这意味着您的整个网站都被认为是西班牙语,但如果您坚持使用测试版,它似乎是其中之一。

我运行进入那个问题(iOS 14.3)。

在iOS中,设置lang属性是不够的。您还需要设置语音属性。

示例:

const utterance = new SpeechSynthesisUtterance('156')
const lang = 'zh-CN'

// Without the following line, voice remains in English on iOS
// voicesList is here the retured value of speechSynthesis.getVoices()
utterance.voice = voicesList.find((voice) => voice.lang === 'zh-CN')

utterance.lang = 'zh-CN'
speechSynthesis.speak(utterance)