【问题标题】:SpeechSynthesisUtterance to use other voice than nativeSpeechSynthesisUtterance 使用非原生语音
【发布时间】:2016-10-28 15:40:29
【问题描述】:

尝试将声音从native 更改为Google US English,但没有成功。这是我正在使用的代码:

https://jsfiddle.net/uv2k0qws/

function speak(text) {
    var msg = new SpeechSynthesisUtterance();
    var voices = speechSynthesis.getVoices();
    msg.volume = 1;
    msg.rate = 1;
    msg.pitch = 2;
    msg.text = text;
    msg.lang = "en-US";
    msg.name = "Google US English";
    msg.voiceURI = "Google US English"
    speechSynthesis.speak(msg);
}
speak('Attention! This is a test.');

有什么线索吗?谢谢

【问题讨论】:

    标签: speech-synthesis


    【解决方案1】:

    这行得通:

        var utterance = new SpeechSynthesisUtterance();
    
        utterance.onstart = function (event) {
            console.log('The utterance started to be spoken.')
        };
    
        window.speechSynthesis.onvoiceschanged = function () {
    
            voices = window.speechSynthesis.getVoices();
            utterance.voice = voices.filter(function (voice) { return voice.lang == 'pt-BR'; })[0];
    
        }
    
    
        $(document).ready(function () {
            utterance.text = "Bom dia amigos!";
            window.speechSynthesis.speak(utterance)
        })
    

    【讨论】:

      【解决方案2】:

      请注意,在 Android Chrome 上设置 utterance.voice 是不够的。虽然它似乎适用于所有其他平台。您还必须设置utterance.lang。这是一个 sn-p,您可能需要在控制台中运行两次才能看到它的工作,因为 speechSynthesis.getVoices 是延迟加载的。

      let utterance = new SpeechSynthesisUtterance("hello");
      let voice = speechSynthesis.getVoices()[0]
      utterance.voice = voice; // required for iOS
      utterance.lang = voice.lang; // required for Android Chrome
      utterance.voiceURI = voice.voiceURI;
      speechSynthesis.speak(utterance);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-17
        • 1970-01-01
        • 2016-02-13
        • 1970-01-01
        • 1970-01-01
        • 2022-06-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多