2016-10-28 14 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) 
    }) 
相關問題