web speech api - speech synthesis .lang property not working

前端 未结 1 1436
傲寒
傲寒 2021-01-22 06:40

im trying to use web speech api to transcript a word in Portuguese, i set the property to \'pt-BR\' ( unfortunately Portuguese - european is not supported) but, always replies i

1条回答
  •  被撕碎了的回忆
    2021-01-22 07:30

    Seems like Chrome broke recently. I had code working, now its not.

    https://code.google.com/p/chromium/issues/detail?id=582455

    As a work-around, you can set the .voice

    voices = window.speechSynthesis.getVoices()
    
    var utterance = new SpeechSynthesisUtterance("lo que practico");
    
    utterance.voice = voices[3];
    utterance.lang = voices[3].lang;
    
    window.speechSynthesis.speak(utterance);
    

    Perhaps the API changed as before when a female/male voice were both available it was not possible to pick one in particular. I still set lang for other browsers (or older chromes).

    0 讨论(0)
提交回复
热议问题