如何通过 Google Chrome 中的 Web Speech API 获取女声 [英] How can I get female voice by Web Speech API in Google Chrome

查看:57
本文介绍了如何通过 Google Chrome 中的 Web Speech API 获取女声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网页中,我想要一个女声来朗读我的文字.我试图通过以下代码来做到这一点.但现在仍然是男声在说话.我怎样才能安排一个女性的声音来说话我的文字?任何人都可以分享我在谷歌浏览器中工作的正确代码.

In a webpage, I want a female voice to speak my texts. I tried to do this by following code. But still now male voice is talking. How can I arrange a female voice to talk my texts? Can anybody share me a correct code that works in Google Chrome.

var voices = speechSynthesis.getVoices();
var msg = new SpeechSynthesisUtterance("Hello World!");
msg.default=false; 
msg.localservice=true;
msg.lang = "en-GB";
msg.voice = voices[3].name;
speechSynthesis.speak(msg);

推荐答案

经过长时间的故障排除,我找到了解决方案.

After a long time of troubleshooting, I could figure out the solution.

4 个人已经向我建议了一些解决方案.但这些对我不起作用.但帮助我找出解决方案.感谢他们所有人.

4 persons already suggested me some solutions. But these did not work for me. But helped me to figure out the solution. Thanks to all of them.

为了解决这个问题,我做了两件事.

To solve the problem, I did two things.

  1. 我必须在 onvoiceschanged 事件期间加载语音,如下所示:

  1. I had to load voices during onvoiceschanged event as follows:

var voices;    
window.speechSynthesis.onvoiceschanged = function() {
    voices=window.speechSynthesis.getVoices();
};

我从 这个链接.

  1. Google 英国英语女性"对我不起作用.所以我使用了Microsoft Zira Desktop - 英语(美国)"如下:

  1. 'Google UK English Female' does not work for me. So I used 'Microsoft Zira Desktop - English (United States)' as follows:

speech.voice = voices.filter(function(voice) { return voice.name == 'Microsoft Zira Desktop - English (United States)'; })[0];

这篇关于如何通过 Google Chrome 中的 Web Speech API 获取女声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆