From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/speechgrammar/index.html | 147 +++++++++++++++++++++ .../web/api/speechgrammar/speechgrammar/index.html | 137 +++++++++++++++++++ files/zh-cn/web/api/speechgrammar/src/index.html | 138 +++++++++++++++++++ .../zh-cn/web/api/speechgrammar/weight/index.html | 138 +++++++++++++++++++ 4 files changed, 560 insertions(+) create mode 100644 files/zh-cn/web/api/speechgrammar/index.html create mode 100644 files/zh-cn/web/api/speechgrammar/speechgrammar/index.html create mode 100644 files/zh-cn/web/api/speechgrammar/src/index.html create mode 100644 files/zh-cn/web/api/speechgrammar/weight/index.html (limited to 'files/zh-cn/web/api/speechgrammar') 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 +--- +

{{APIRef("Web Speech API")}}{{SeeCompatTable}}

+ +

Web Speech API 的 SpeechGrammar 接口 表示了语音识别对象服务想要识别的一系列词语或模式。

+ +

文法通过 JSpeech Grammar Format (JSGF.) 来定义,其他格式的文法会在以后支持。

+ +

构造函数

+ +
+
{{domxref("SpeechGrammar.SpeechGrammar()")}}
+
创建一个新的 SpeechGrammar 对象。
+
+ +

属性

+ +
+
{{domxref("SpeechGrammar.src")}}
+
设置或返回 SpeechGrammar 对象实例中包含文法的字符串。
+
{{domxref("SpeechGrammar.weight")}} {{optional_inline}}
+
设置或返回 SpeechGrammar 对象的权重。
+
+ +

示例

+ +
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 - 与上面第四行所设置的权重一致
+
+ +

规格

+ + + + + + + + + + + + + + +
规格状态描述
{{SpecName('Web Speech API', '#speechreco-speechgrammar', 'SpeechGrammar')}}{{Spec2('Web Speech API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(33)}} [1]{{CompatGeckoDesktop(44)}} [2]{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}[1]{{CompatUnknown}}2.5{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ + + +

Firefox OS 权限

+ +

如需在应用中使用语音识别,你必须在你的 manifest 中指明下面的权限:

+ +
"permissions": {
+  "audio-capture" : {
+    "description" : "Audio capture"
+  },
+  "speech-recognition" : {
+    "description" : "Speech recognition"
+  }
+}
+ +

若还需要设置应用的特权类型,因此你还需要包含以下这项:

+ +
  "type": "privileged"
+ +

相关链接

+ + 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 +--- +

{{APIRef("Web Speech API")}}{{SeeCompatTable}}

+ +

SpeechGrammar 是 {{domxref("SpeechGrammar")}} 接口的构造函数,创建一个新的 SpeechGrammar 对象实例。

+ +

语法

+ +
var mySpeechGrammar = new SpeechGrammar();
+ +

Parameters

+ +

无。

+ +

样例

+ +
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 对象添加到列表中
+
+ +

规格

+ + + + + + + + + + + + + + +
规格状态描述
{{SpecName('Web Speech API', '#speechreco-section', 'SpeechGrammar()')}}{{Spec2('Web Speech API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(33)}} [1]{{CompatGeckoDesktop(44)}} [2]{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}[1]{{CompatUnknown}}2.5{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ + + +

Firefox OS 权限

+ +

如需在应用中使用语音识别,你必须在你的 manifest 中指明下面的权限:

+ +
"permissions": {
+  "audio-capture" : {
+    "description" : "Audio capture"
+  },
+  "speech-recognition" : {
+    "description" : "Speech recognition"
+  }
+}
+ +

若还需要设置应用的特权类型,因此你还需要包含以下这项:

+ +
  "type": "privileged"
+ +

相关链接

+ + 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 +--- +

{{APIRef("Web Speech API")}}{{SeeCompatTable}}

+ +

src 属性是 {{domxref("SpeechGrammar")}} 接口设置并返回的一个字符串,包含了 SpeechGrammar 对象的文法。

+ +

语法

+ +
var myGrammar = speechGrammarInstance.src;
+ +

+ +

{{domxref("DOMString")}} 用以表示文法。

+ +

示例

+ +
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 - 与上面第四行所设置的权重一致
+
+ +

规格

+ + + + + + + + + + + + + + +
规格状态描述
{{SpecName('Web Speech API', '#dfn-grammarSrc', 'src')}}{{Spec2('Web Speech API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(33)}} [1]{{CompatGeckoDesktop(44)}} [2]{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}[1]{{CompatUnknown}}2.5{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ + + +

Firefox OS 权限

+ +

如需在应用中使用语音识别,你必须在你的 manifest 中指明下面的权限:

+ +
"permissions": {
+  "audio-capture" : {
+    "description" : "Audio capture"
+  },
+  "speech-recognition" : {
+    "description" : "Speech recognition"
+  }
+}
+ +

若还需要设置应用的特权类型,因此你还需要包含以下这项:

+ +
  "type": "privileged"
+ +

相关链接

+ + 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 +--- +

{{APIRef("Web Speech API")}}{{SeeCompatTable}}

+ +

{{domxref("SpeechGrammar")}} 接口的可选属性 weight 设置并返回了一个  SpeechGrammar 对象的权重。

+ +

语法

+ +
var myGrammarWeight = speechGrammarInstance.weight;
+ +

+ +

浮点数表示了当前文法的权重,范围在 0.0-1.0 之间。

+ +

样例

+ +
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 - 与上面第四行所设置的权重一致
+
+ +

规格

+ + + + + + + + + + + + + + +
规格状态描述
{{SpecName('Web Speech API', '#dfn-grammarWeight', 'weight')}}{{Spec2('Web Speech API')}} 
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(33)}} [1]{{CompatGeckoDesktop(44)}} [2]{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChromeFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}[1]{{CompatUnknown}}2.5{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ + + +

Firefox OS 权限

+ +

如需在应用中使用语音识别,你必须在你的 manifest 中指明下面的权限:

+ +
"permissions": {
+  "audio-capture" : {
+    "description" : "Audio capture"
+  },
+  "speech-recognition" : {
+    "description" : "Speech recognition"
+  }
+}
+ +

若还需要设置应用的特权类型,因此你还需要包含以下这项:

+ +
  "type": "privileged"
+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf