text-to-speech - SpeechSynthesis 无法用葡萄牙语说话 (pt-BR)

标签 text-to-speech speech-synthesis webspeech-api google-speech-api

我正在编写一段 JavaScript 代码,希望用户在单击“开始按钮”时对其表示欢迎。它可以用英语工作,但重点是我希望它用巴西葡萄牙语 (pt-BR) 说话。我尝试了很多解决方案,但似乎不起作用。有人可以帮我吗?

代码是:

<!DOCTYPE html>
<html lang="pt-BR">
<head>
<script>

startTalking = function(line){
    var text  = new SpeechSynthesisUtterance();
    text.lang = "pt-BR";
    text.text = line;
    speechSynthesis.speak(text);
  }

</script>
</head>
<body>

<button id="startButton" onclick = "startTalking("Bem vindo!")"></button>

</body>
</html>

当我单击按钮时,脚本会起作用,但参数中收到的文本是由英语(美国)语音朗读的。

有人知道如何修复它吗?

谢谢!!

最佳答案

感谢您的回复布鲁诺。我在发布问题的第二天就解决了这种情况,但无法在此处发布解决方案。我用这个解决了这种情况:

<!DOCTYPE html>
<html lang="pt-BR">
<head>
<script>

var text;
var voices;

window.speechSynthesis.onvoiceschanged = function() {
  text = new SpeechSynthesisUtterance();
  voices = window.speechSynthesis.getVoices();
  text.voiceURI = 'Google português do Brasil'; //discovered after dumping getVoices()
  text.lang = "pt-BR";
  text.localService = true;
  text.voice = voices[15]; //index to the voiceURI. This index number is not static.
}

startSpeaking = function(line){
  text.text = line;
  speechSynthesis.speak(text);
}

</script>
</head>
<body>

<button id="startButton" onclick = "startTalking("Bem vindo!")"></button>

</body>
</html>

一旦 onvoiceschanged 是异步的,这使得现在一切正常!

虽然我已经解决了,但还是非常感谢你的回复。非常感谢。

最诚挚的问候,

尤利西斯

关于text-to-speech - SpeechSynthesis 无法用葡萄牙语说话 (pt-BR),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36485170/

相关文章:

php - php 中的谷歌云文本转语音

c# - System.Speech.Synthesis 在 2012 R2 上因高 CPU 而挂起

.net - 使用 SpeechSynthesizer 使用 SpeechAudioFormatInfo 流式传输 TTS

javascript - 如何在 Chromium 上使用 Web Speech API?

javascript - Angular 2 : Web Speech API - Voice recognition

android - 无法检测到 TTS(回调)android 的完成。

Android 印度尼西亚语文本转语音

java - Android 文本转语音不适用于/日语

java - 语音合成空指针异常

webspeech-api - 如何列出并允许选择用于 WebSpeech API 的输入设备?