我目前正在做一些关于 Webkit 语音识别的 RnD,我想创建一个特定于应用程序的语法文件。根据 W3C 定义,我编写了以下代码。但它似乎并没有显示出对这些词的识别改进的结果。你能提供一些帮助吗?
var 识别 = 新 webkitSpeechRecognition(); 识别.grammars.addFromUri("voice/api_grammar/weight.grxml");
语法文件是一个简单的文件,如下所示。
<?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>