HTML5语音识别---有没有办法设置用户预期的动态动态? (使用自定义语法) [英] HTML5 Speech recognition --- is there a way to set what the user is expected to say dynamically? (Using custom Grammars)
问题描述
我正在寻找一种方法来定义您希望用户在< input>
标签
中使用HTML 5 语言
属性集。
我知道您可以通过语法
属性指定特定的语法,
这样:
< input type =textspeech grammar =grammar.grxml/>
(请参阅 http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html )
但是我希望有一种方式使这个动态,所以我可以指定我期望用户通过javascript说。
例如,如果您有动态生成的项目列表供用户从语音中选择,那么您将如何指定他们会说的内容最有可能是一个的那些项目?
我正在使用Google Chrome进行测试,因此使用 x-webkit-speech
属性而不是语音
,同样 x-webkit-grammar
而不是语法
。
我找到了一种方法来做客户端,使用新的html5功能: blobs 。
window.URL = window.URL || window.webkitURL;
var myGrammar = new Blob([我的自定义语法],{
类型:'text / xml或任何适用于语法的MIME类型}};
var grammarUrl = window.URL.createObjectURL(myGrammar);
myInput = document.getElementById(myInput);
myInput.grammar = grammarUrl;
这将使一个url超出语法字符串,然后设置我们的输入
元素。
这样就不需要做出服务器请求,从而使服务器的加载速度更快,更少。有关blob的更多信息,请参阅这个和这个。
I am looking for a way to define what you expect the user to say in an <input>
tag
with the HTML 5 speech
attribute set.
I know that you can specify a specific grammar to use via the grammar
attribute,
like this:
<input type="text" speech grammar="grammar.grxml" />
( see http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html )
but I was hoping for a way to make this dynamic, so that I can specify what I expect the user to say via javascript.
For example, if you had a dynamically generated list of items for a user to select from by speech, how would you specify that what they will say will most likely be one of those items?
P.S. I am testing this with Google Chrome, thus using the x-webkit-speech
attribute instead of speech
and likewise x-webkit-grammar
instead of grammar
.
I found a way to do it client-side, using a new html5 feature: blobs.
window.URL = window.URL || window.webkitURL;
var myGrammar = new Blob(["My custom grammar"], {
type: 'text/xml Or whatever is the proper MIME type for grammars'});
var grammarUrl = window.URL.createObjectURL(myGrammar);
myInput = document.getElementById("myInput");
myInput.grammar = grammarUrl;
This makes a url out of the grammar string, and then sets that url for our input
element.
This way there is no need to make a server request, thus making it faster and less load on the server.
For more information on blobs, see this and this.
这篇关于HTML5语音识别---有没有办法设置用户预期的动态动态? (使用自定义语法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!