以下HTML在第一次单击时在控制台中显示空数组:
<!DOCTYPE html>
<html>
<head>
<script>
function test(){
console.log(window.speechSynthesis.getVoices())
}
</script>
</head>
<body>
<a href="#" onclick="test()">Test</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在第二次单击中,您将获得预期的列表.
如果添加onload
事件来调用此函数(<body onload="test()">
),则可以在第一次单击时获得正确的结果.请注意,第一次调用onload
仍然无法正常工作.它在页面加载时返回空,但后续工作.
问题:
由于它可能是测试版中的错误,我放弃了"为什么"的问题.
现在,问题是您是否要window.speechSynthesis
在页面加载时访问:
speechSynthesis
在页面加载时确保它会加载?背景和测试:
我正在测试Web Speech API中的新功能,然后我在我的代码中遇到了这个问题:
<script type="text/javascript">
$(document).ready(function(){
// Browser support messages. (You might need Chrome 33.0 Beta)
if (!('speechSynthesis' in window)) {
alert("You don't have speechSynthesis");
}
var voices = window.speechSynthesis.getVoices();
console.log(voices) // []
$("#test").on('click', function(){
var voices = window.speechSynthesis.getVoices();
console.log(voices); // …
Run Code Online (Sandbox Code Playgroud) 我正在进行网络语音识别.
我发现Google为开发人员提供了一个名为"Google speech API V2"的API.但我注意到每天都有限制使用它.
之后我发现有一个原生的WEB Speech API也可以实现语音识别.它只是在谷歌Chrome和歌剧:
http://caniuse.com/#feat=speech-recognition
那么1.什么是不同的Google Speech API和Web Speech API?他们有关系吗?
谢谢.
如何使用SpeechSynthesisUtterance()
及window.speechSynthesis.speak()
在Chromium浏览器?
var msg = new SpeechSynthesisUtterance( "Hello I am browser" );
window.speechSynthesis.speak( msg );
Run Code Online (Sandbox Code Playgroud)
系统扬声器没有输出.
已经注意到API的问题HTML5 SpeechSynthesis API是垃圾 ;
var voices = window.speechSynthesis.getVoices();
Run Code Online (Sandbox Code Playgroud)
记录voices
标识符的空数组; 并且只有chrome not chromium据称支持Web Speech API规范,Web Speech API Demonstrationhtml
在演示时将元素的值设置为在页面启用麦克风时发声的话语.
至少有一些与功能相关的JavaScript显然是
var langs =
[['Afrikaans', ['af-ZA']],
['Bahasa Indonesia',['id-ID']],
['Bahasa Melayu', ['ms-MY']],
['Català', ['ca-ES']],
['?eština', ['cs-CZ']],
['Dansk', ['da-DK']],
['Deutsch', ['de-DE']],
['English', ['en-AU', 'Australia'],
['en-CA', 'Canada'],
['en-IN', 'India'],
['en-NZ', 'New Zealand'],
['en-ZA', 'South Africa'],
['en-GB', 'United Kingdom'],
['en-US', …
Run Code Online (Sandbox Code Playgroud) 在阅读了webkitSpeechRecognition(Javascript中的语音识别)的文档后,我尝试在Angular 2中实现它.
但是当我这样做时:
const recognition = new webkitSpeechRecognition();
Run Code Online (Sandbox Code Playgroud)
TypeScript说这个错误:
[ts] Cannot find name 'webkitSpeechRecognition'. any
Run Code Online (Sandbox Code Playgroud)
如果我尝试从窗口中提取webkitSpeechRecognition:
if ('webkitSpeechRecognition' in window) {
console.log("Enters inside the condition"); // => It's printing
const { webkitSpeechRecognition } = window; // => TypeScript Error
const recognition = new webkitSpeechRecognition();
}
Run Code Online (Sandbox Code Playgroud)
如果我评论console.log
打印的最后两行,请进入条件!webkitSpeechRecognition存在于窗口内!但是如果没有注释最后两行,那么TypeScript错误就是这样:
[ts] Type 'Window' has no property 'webkitSpeechRecognition' and no string index signature.
const webkitSpeechRecognition: any
Run Code Online (Sandbox Code Playgroud)
如何在Angular 2中创建新的识别?有人试过吗?
javascript voice-recognition webspeech-api typescript1.8 angular
当speak
在Web Speech API中使用该功能时,在Chrome中,语音在几秒钟之后突然停止,在给予它的文本中间,在一个看似随机的地方(没有到达终点).这只发生在Chrome(适用于Firefox),在两台不同的计算机/系统上进行测试.
看看这个jsfiddle看/听:https://jsfiddle.net/fv9ochpq/
您可以看到SpeechSynthesis
对象.speaking
标志在停止讲话后保持打开(true).
我没有看到传递给话语的文本有任何记录限制.这是Google Chrome错误吗?顺便说一下,自2014年以来我就已经知道了这一点 - 当时我试图将语音功能添加到我制作的浏览器扩展中(那时它是可用于Chrome扩展的TTS API - 同样的事情也发生在那里),但最终还没有不要因为这个明显的错误而这样做.现在我想要克服这个问题 - 如果这是一个错误,我会感谢任何人指导我到最好的地方报告它.
编辑:它似乎在大约15秒后停止.每运行14秒添加一个间隔.resume()
似乎"修复"了这个.请参阅:https ://jsfiddle.net/fv9ochpq/1/
但这是一个黑客攻击.
javascript google-chrome text-to-speech speech-synthesis webspeech-api
text属性
此属性指定要为此话语合成和说出的文本.这可以是纯文本或完整的,格式良好的SSML文档.对于不支持SSML或仅支持某些标签的语音合成引擎,用户代理或语音引擎必须剥离它们不支持的标签并说出文本.
它没有提供使用text
SSML文档的示例.
我在Chrome 33中尝试了以下内容:
var msg = new SpeechSynthesisUtterance();
msg.text = '<?xml version="1.0"?>\r\n<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">ABCD</speak>';
speechSynthesis.speak(msg);
Run Code Online (Sandbox Code Playgroud)
它不起作用 - 声音试图叙述XML标签.这段代码有效吗?
我必须提供一个XMLDocument
对象吗?
我试图了解Chrome是否违反了规范(应该将其报告为错误),或者我的代码是否无效.
我有一个问题,在Firefox中,如果页面自动刷新,语音会被截断,但是在谷歌浏览器中,即使页面是自动刷新的,语音也会结束。我如何解决这个问题,以便即使页面自动刷新也不会在Firefox中被切断?
msg = new SpeechSynthesisUtterance("please finish saying this entire sentence.");
window.speechSynthesis.speak(msg);
(function ($) {
'use strict';
if (window == window.top) {
var body = $('body').empty();
var myframe = $('<iframe>')
.attr({ src: location.href })
.css({ height: '95vh', width: '100%' })
.appendTo(body)
.on('load', function () {
var interval;
interval = 750;
setTimeout(function () {
myframe.attr({ src: location.href });
}, interval);
});
}
})(jQuery);
Run Code Online (Sandbox Code Playgroud) 我有一个PHP Web应用程序,我正在寻找一个开源,高精度的语音到文本识别实现,它将采用语音命令打开用户的网页.示例:" Make Sales "(这将打开Create Sales PHP页面)," Make Purchase order "," Open END-OF-DAY reports "等.
我的问题:
我想知道我们是否可以使用Mozilla DeepSpeech从Firefox浏览器中获取.wav音频并将语音返回文本.如果是的话,使用话筒从Firefox录制语音的流量是什么?使用DeepSpeech引擎转换文本?
如何制作类似于OK-GOOGLE的唤醒/启动呼叫,它将准备好侦听命令?
php speech-recognition speech-to-text webspeech-api mozilla-deepspeech
在Web Speech API的示例中,始终指定语法.例如,在MDN的颜色更改示例中,语法为:
#JSGF V1.0;
grammar colors;
public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | …
Run Code Online (Sandbox Code Playgroud) 我在Windows 10上使用Chrome版本55.0.2883.87 m(64位).
以下简单的html文件重现了该问题,并从我更复杂的应用程序中提取.它应该在页面加载时说出3个单词.它适用于MS Edge和Firefox,但不适用于chrome.几个星期前,这段代码在我的Chrome上工作没问题.
<html>
<head>
<script lang="javascript">
window.speechSynthesis.speak(new SpeechSynthesisUtterance("cat"));
window.speechSynthesis.speak(new SpeechSynthesisUtterance("dog"));
window.speechSynthesis.speak(new SpeechSynthesisUtterance("bark"));
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud) webspeech-api ×10
javascript ×5
angular ×1
chromium ×1
dom-events ×1
html5 ×1
parsing ×1
php ×1
refresh ×1
voice ×1