diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/speechgrammar | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/speechgrammar')
-rw-r--r-- | files/zh-cn/web/api/speechgrammar/index.html | 147 | ||||
-rw-r--r-- | files/zh-cn/web/api/speechgrammar/speechgrammar/index.html | 137 | ||||
-rw-r--r-- | files/zh-cn/web/api/speechgrammar/src/index.html | 138 | ||||
-rw-r--r-- | files/zh-cn/web/api/speechgrammar/weight/index.html | 138 |
4 files changed, 560 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/speechgrammar/index.html b/files/zh-cn/web/api/speechgrammar/index.html new file mode 100644 index 0000000000..91f25491c7 --- /dev/null +++ b/files/zh-cn/web/api/speechgrammar/index.html @@ -0,0 +1,147 @@ +--- +title: SpeechGrammar +slug: Web/API/SpeechGrammar +tags: + - API + - SpeechGrammar + - Web Speech API + - 实验性 + - 接口 + - 识别 + - 语音 + - 语音识别 +translation_of: Web/API/SpeechGrammar +--- +<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p> + +<p><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> 的 <strong><code>SpeechGrammar</code></strong> 接口 表示了语音识别对象服务想要识别的一系列词语或模式。</p> + +<p>文法通过 <a class="external external-icon" href="http://www.w3.org/TR/jsgf/">JSpeech Grammar Format</a> (<strong>JSGF</strong>.) 来定义,其他格式的文法会在以后支持。</p> + +<h2 id="构造函数">构造函数</h2> + +<dl> + <dt>{{domxref("SpeechGrammar.SpeechGrammar()")}}</dt> + <dd>创建一个新的 <code>SpeechGrammar</code> 对象。</dd> +</dl> + +<h2 id="属性">属性</h2> + +<dl> + <dt>{{domxref("SpeechGrammar.src")}}</dt> + <dd>设置或返回 <code>SpeechGrammar</code> 对象实例中包含文法的字符串。</dd> + <dt>{{domxref("SpeechGrammar.weight")}} {{optional_inline}}</dt> + <dd>设置或返回 <code>SpeechGrammar</code> 对象的权重。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">var grammar = '#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 | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;' +var recognition = new SpeechRecognition(); +var speechRecognitionList = new SpeechGrammarList(); +speechRecognitionList.addFromString(grammar, 1); +recognition.grammars = speechRecognitionList; + + +console.log(speechRecognitionList[0].src); // 应该返回和上面语法变量一样的内容 +console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第四行所设置的权重一致 +</pre> + +<h2 id="规格">规格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格</th> + <th scope="col">状态</th> + <th scope="col">描述</th> + </tr> + <tr> + <td>{{SpecName('Web Speech API', '#speechreco-speechgrammar', 'SpeechGrammar')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] 语音识别接口目前在 Chrome 中是带前缀的,因此你需要使用带有前缀的名称,例如 <code>webkitSpeechRecognition</code>;此外你还需要将你的代码运行在一个 Web 服务器上来保证其正常工作。</li> + <li>[2] 虽然当前的语音识别在桌面版的 Firefox 中不会正常工作,但还是可以在 <a>about:config</a>中,可以通过 <code>media.webspeech.recognition.enable</code> 来启用 —— 一旦所需的内部权限解决后,它很快就会启用。</li> +</ul> + +<h3 id="Firefox_OS_权限">Firefox OS 权限</h3> + +<p>如需在应用中使用语音识别,你必须在你的 <a href="https://developer.mozilla.org/en-US/docs/Web/Apps/Build/Manifest">manifest</a> 中指明下面的权限:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>若还需要设置应用的特权类型,因此你还需要包含以下这项:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> +</ul> diff --git a/files/zh-cn/web/api/speechgrammar/speechgrammar/index.html b/files/zh-cn/web/api/speechgrammar/speechgrammar/index.html new file mode 100644 index 0000000000..c18e560e57 --- /dev/null +++ b/files/zh-cn/web/api/speechgrammar/speechgrammar/index.html @@ -0,0 +1,137 @@ +--- +title: SpeechGrammar.SpeechGrammar() +slug: Web/API/SpeechGrammar/SpeechGrammar +tags: + - API + - SpeechGrammar + - Web + - Web Speech API + - 实验性 + - 引用 + - 构造函数 + - 语音识别 +translation_of: Web/API/SpeechGrammar/SpeechGrammar +--- +<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p> + +<p><code><strong>SpeechGrammar</strong></code> 是 {{domxref("SpeechGrammar")}} 接口的构造函数,创建一个新的 <code>SpeechGrammar</code> 对象实例。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var mySpeechGrammar = new SpeechGrammar();</pre> + +<h3 id="Parameters">Parameters</h3> + +<p>无。</p> + +<h2 id="样例">样例</h2> + +<pre class="brush: js">var grammar = '#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 | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;' +var recognition = new SpeechRecognition(); +var speechRecognitionList = new SpeechGrammarList(); +speechRecognitionList.addFromString(grammar, 1); +recognition.grammars = speechRecognitionList; + +var newGrammar = new SpeechGrammar(); +newGrammar.src = '#JSGF V1.0; grammar names; public <name> = chris | kirsty | mike;' +speechRecognitionList[1] = newGrammar; // 将 SpeechGrammar 对象添加到列表中 +</pre> + +<h2 id="规格">规格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格</th> + <th scope="col">状态</th> + <th scope="col">描述</th> + </tr> + <tr> + <td>{{SpecName('Web Speech API', '#speechreco-section', 'SpeechGrammar()')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] 语音识别接口目前在 Chrome 中是带前缀的,因此你需要使用带有前缀的名称,例如 <code>webkitSpeechRecognition</code>;此外你还需要将你的代码运行在一个 Web 服务器上来保证其正常工作。</li> + <li>[2] 虽然当前的语音识别在桌面版的 Firefox 中不会正常工作,但还是可以在 <a>about:config</a>中,可以通过 <code>media.webspeech.recognition.enable</code> 来启用 —— 一旦所需的内部权限解决后,它很快就会启用。</li> +</ul> + +<h3 id="Firefox_OS_权限">Firefox OS 权限</h3> + +<p>如需在应用中使用语音识别,你必须在你的 <a href="https://developer.mozilla.org/en-US/docs/Web/Apps/Build/Manifest">manifest</a> 中指明下面的权限:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>若还需要设置应用的特权类型,因此你还需要包含以下这项:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> +</ul> diff --git a/files/zh-cn/web/api/speechgrammar/src/index.html b/files/zh-cn/web/api/speechgrammar/src/index.html new file mode 100644 index 0000000000..4c3d7f2712 --- /dev/null +++ b/files/zh-cn/web/api/speechgrammar/src/index.html @@ -0,0 +1,138 @@ +--- +title: SpeechGrammar.src +slug: Web/API/SpeechGrammar/src +tags: + - API + - SpeechGrammar + - Web Speech API + - src + - 实验性 + - 属性 + - 引用 + - 识别 + - 语音 +translation_of: Web/API/SpeechGrammar/src +--- +<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p> + +<p><code><strong>src</strong></code> 属性是 {{domxref("SpeechGrammar")}} 接口设置并返回的一个字符串,包含了 <code>SpeechGrammar</code> 对象的文法。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var myGrammar = speechGrammarInstance.src;</pre> + +<h3 id="值">值</h3> + +<p>{{domxref("DOMString")}} 用以表示文法。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">var grammar = '#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 | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;' +var recognition = new SpeechRecognition(); +var speechRecognitionList = new SpeechGrammarList(); +speechRecognitionList.addFromString(grammar, 1); +recognition.grammars = speechRecognitionList; + + +console.log(speechRecognitionList[0].src); // 应该返回和上面文法变量一样的内容 +console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第四行所设置的权重一致 +</pre> + +<h2 id="规格">规格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格</th> + <th scope="col">状态</th> + <th scope="col">描述</th> + </tr> + <tr> + <td>{{SpecName('Web Speech API', '#dfn-grammarSrc', 'src')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] 语音识别接口目前在 Chrome 中是带前缀的,因此你需要使用带有前缀的名称,例如 <code>webkitSpeechRecognition</code>;此外你还需要将你的代码运行在一个 Web 服务器上来保证其正常工作。</li> + <li>[2] 虽然当前的语音识别在桌面版的 Firefox 中不会正常工作,但还是可以在 <a>about:config</a>中,可以通过 <code>media.webspeech.recognition.enable</code> 来启用 —— 一旦所需的内部权限解决后,它很快就会启用。</li> +</ul> + +<h3 id="Firefox_OS_权限">Firefox OS 权限</h3> + +<p>如需在应用中使用语音识别,你必须在你的 <a href="https://developer.mozilla.org/en-US/docs/Web/Apps/Build/Manifest">manifest</a> 中指明下面的权限:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>若还需要设置应用的特权类型,因此你还需要包含以下这项:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> +</ul> diff --git a/files/zh-cn/web/api/speechgrammar/weight/index.html b/files/zh-cn/web/api/speechgrammar/weight/index.html new file mode 100644 index 0000000000..3a56e9edad --- /dev/null +++ b/files/zh-cn/web/api/speechgrammar/weight/index.html @@ -0,0 +1,138 @@ +--- +title: SpeechGrammar.weight +slug: Web/API/SpeechGrammar/weight +tags: + - API + - SpeechGrammar + - Web Speech API + - 实验性 + - 属性 + - 引用 + - 权重 + - 识别 + - 语音识别 +translation_of: Web/API/SpeechGrammar/weight +--- +<p>{{APIRef("Web Speech API")}}{{SeeCompatTable}}</p> + +<p>{{domxref("SpeechGrammar")}} 接口的可选属性 <strong><code>weight</code></strong> 设置并返回了一个 <code>SpeechGrammar</code> 对象的权重。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var myGrammarWeight = speechGrammarInstance.weight;</pre> + +<h3 id="值">值</h3> + +<p>浮点数表示了当前文法的权重,范围在 0.0-1.0 之间。</p> + +<h2 id="样例">样例</h2> + +<pre class="brush: js">var grammar = '#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 | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;' +var recognition = new SpeechRecognition(); +var speechRecognitionList = new SpeechGrammarList(); +speechRecognitionList.addFromString(grammar, 1); +recognition.grammars = speechRecognitionList; + + +console.log(speechRecognitionList[0].src); // 应该返回和上面文法变量一样的内容 +console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第四行所设置的权重一致 +</pre> + +<h2 id="规格">规格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规格</th> + <th scope="col">状态</th> + <th scope="col">描述</th> + </tr> + <tr> + <td>{{SpecName('Web Speech API', '#dfn-grammarWeight', 'weight')}}</td> + <td>{{Spec2('Web Speech API')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(33)}} <sup>[1]</sup></td> + <td>{{CompatGeckoDesktop(44)}} <sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}<sup>[1]</sup></td> + <td>{{CompatUnknown}}</td> + <td>2.5</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>[1] 语音识别接口目前在 Chrome 中是带前缀的,因此你需要使用带有前缀的名称,例如 <code>webkitSpeechRecognition</code>;此外你还需要将你的代码运行在一个 Web 服务器上来保证其正常工作。</li> + <li>[2] 虽然当前的语音识别在桌面版的 Firefox 中不会正常工作,但还是可以在 <a>about:config</a> 中,可以通过 <code>media.webspeech.recognition.enable</code> 来启用 —— 一旦所需的内部权限解决后,它很快就会启用。</li> +</ul> + +<h3 id="Firefox_OS_权限">Firefox OS 权限</h3> + +<p>如需在应用中使用语音识别,你必须在你的 <a href="/en-US/docs/Web/Apps/Build/Manifest">manifest</a> 中指明下面的权限:</p> + +<pre class="brush: json">"permissions": { + "audio-capture" : { + "description" : "Audio capture" + }, + "speech-recognition" : { + "description" : "Speech recognition" + } +}</pre> + +<p>若还需要设置应用的特权类型,因此你还需要包含以下这项:</p> + +<pre class="brush: json"> "type": "privileged"</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a></li> +</ul> |