This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
A propriedade voice
da interface SpeechSynthesisUtterance
retorna e configura a voz que será usada para a fala.
Essa propriedade deve ser configurada para um dos objetos SpeechSynthesisVoice
retornado por SpeechSynthesis.getVoices()
. Se não for configurada no momento da fala, a voz usada será a determinada como default na propriedade lang
.
Sintaxe
var myVoice = speechSynthesisUtteranceInstance.voice; speechSynthesisUtteranceInstance.voice = speechSynthesisVoiceInstance;
Valor
Um objeto SpeechSynthesisVoice
.
Examplo
var synth = window.speechSynthesis;
var inputForm = document.querySelector('form');
var inputTxt = document.querySelector('input');
var voiceSelect = document.querySelector('select');
var voices = synth.getVoices();
...
inputForm.onsubmit = function(event) {
event.preventDefault();
var utterThis = new SpeechSynthesisUtterance(inputTxt.value);
var selectedOption = voiceSelect.selectedOptions[0].getAttribute('data-name');
for(i = 0; i < voices.length ; i++) {
if(voices[i].name === selectedOption) {
utterThis.voice = voices[i];
}
}
synth.speak(utterThis);
inputTxt.blur();
}
Especificações
Especificação | Status | Comentário |
---|---|---|
Web Speech API The definition of 'voice' in that specification. |
Draft |
Compatiblidade dos navegadores
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 33 | 49 (49) | Não suportado | ? | 7 |
Feature | Android | Chrome | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | Não suportado | 2.0 | Não suportado | Não suportado | 7.1 |