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