2016-10-28 13 views
0

尝试将语音从native更改为Google US English,但没有成功。这是我使用的代码:SpeechSynthesis话语使用其他语音而不是原生

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.'); 

任何线索?谢谢

回答

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) 
    }) 
相关问题