本文介绍了Web Speech API语法是否暴露给开发人员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Webkit语音识别上做了一些RnD,我想创建一个特定于应用程序的语法文件。
根据W3C定义,我写了下面的代码。但它似乎并没有显示出对这些词的认可有了改进的结果。您可以提供一些帮助。



var recognition = new webkitSpeechRecognition();
recognition.grammars.addFromUri(voice / api_grammar / weight.grxml);

语法文件是一个简单的文件,如下所示。

 <?xml version =1.0encoding =UTF-8?> 

<!DOCTYPE grammar PUBLIC - // W3C // DTD GRAMMAR 1.0 // EN
http://www.w3.org/TR/speech-grammar/grammar .dtd>

xmlns =http://www.w3.org/2001/06/grammar
xmlns:xsi =http: //www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://www.w3.org/2001/06/grammar
http://www.w3。 org / TR / speech-grammar / grammar.xsd
xml:lang =en-USmode =voiceroot =sequence>

< meta name ='description'content ='使用示例的示例'/>

< meta name ='in.1'content ='sunny Yorktown Heights New York United States'/>




< rule id =ruleref>
< example>Yorktown Heights< / example>
< ruleref uri =#token/>
< / rule>

< rule id =alternatives>
< example> sunny< / example>
<例子>多云< / example>
< example> warm< / example>
< example> cold< / example>
< one-of>
< item>晴天< / item>
< item>阴天< / item>
< item>温暖< / item>
< item>冷< / item>
< / one-of>
< / rule>

< rule id =repeat>
< example>< / example> <! - for count = 0 - >
< example> warm< / example>
<示例>暖和晴天< / example>
< item repeat =0-3>
< ruleref uri =#alternatives/>
< / item>
< / rule>

< rule id =sequence>
<示例>
温暖晴朗多云Yorktown Heights纽约美国
< / example>
<示例>
温暖晴朗多云Yorktown Heights纽约United
States
< / example>
<示例> <! - 这个例子实际上是错的,但这是合法的 - >
温暖晴朗多云Yorktown Heights纽约美国
< / example>

< ruleref uri =#repeat/> < ruleref uri =#ruleref/>
< ruleref uri =#Token/> < ruleref uri =#TOKEN/>
< / rule>

< /语法>


解决方案

虽然w3c指定了网络语音的语法,尚未由Chrome实施。

I am currently doing some RnD on Webkit Speech Recognition and I wanted to create an application specific grammar file.According W3C definition I wrote the following code. But it doesnt seem to show improved results in recognition for these words. Can you kindly provide some help with this.?

var recognition = new webkitSpeechRecognition();recognition.grammars.addFromUri("voice/api_grammar/weight.grxml");

The grammar file is a simple file which looked like the following.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE grammar PUBLIC "-//W3C//DTD GRAMMAR 1.0//EN"
                  "http://www.w3.org/TR/speech-grammar/grammar.dtd">

<grammar version="1.0"
         xmlns="http://www.w3.org/2001/06/grammar"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://www.w3.org/2001/06/grammar 
                             http://www.w3.org/TR/speech-grammar/grammar.xsd"
         xml:lang="en-US" mode="voice" root="sequence">

  <meta name='description' content='Example using examples'/>

  <meta name='in.1' content='sunny Yorktown Heights New York United States'/>
  <meta name='out.1' content='$sequence[$repeat[$alternatives["sunny"]],$ruleref[$token["Yorktown Heights"]],$Token["New","York"],$TOKEN["United States"]]'/>




  <rule id="ruleref">
    <example>"Yorktown Heights"</example>
    <ruleref uri="#token"/>
  </rule>

  <rule id="alternatives">
    <example>sunny</example>
    <example>cloudy</example>
    <example>warm</example>
    <example>cold</example>
    <one-of>
      <item> sunny </item>
      <item> cloudy </item>
      <item> warm </item>
      <item> cold </item>
    </one-of>
  </rule>

  <rule id="repeat">
   <example></example> <!-- for count=0 -->
   <example>warm</example>
   <example>warm sunny cloudy</example>
   <item repeat="0-3">
      <ruleref uri="#alternatives"/>
   </item>
  </rule>

  <rule id="sequence">
    <example>
      warm sunny cloudy "Yorktown Heights" New York "United States"
    </example>
    <example>
      warm sunny cloudy   Yorktown   Heights   New York United
            States
    </example>
    <example> <!-- this example is actually wrong but that is legal -->
      warm sunny cloudy "Yorktown   Heights" New York "United States"
    </example>

    <ruleref uri="#repeat"/> <ruleref uri="#ruleref"/>
    <ruleref uri="#Token"/> <ruleref uri="#TOKEN"/>    
  </rule>

</grammar>
解决方案

Though w3c specified the grammar for web speech it is not yet implemented by the chrome.

这篇关于Web Speech API语法是否暴露给开发人员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 01:37