Skip to content

Commit

Permalink
[zh-cn]: update the translation of SpeechGrammar weight property (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
T34-active authored Jul 19, 2024
1 parent 59db55c commit e464daa
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions files/zh-cn/web/api/speechgrammar/weight/index.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
---
title: SpeechGrammar.weight
title: SpeechGrammarweight 属性
slug: Web/API/SpeechGrammar/weight
l10n:
sourceCommit: 23e1a97d50050a3b3518a4b2f67ccf42e5fd75b7
---

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

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

## 语法
##

```plain
var myGrammarWeight = speechGrammarInstance.weight;
```

###

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

## 样例
## 示例

```js
var grammar =
const 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();
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;

console.log(speechRecognitionList[0].src); // 应该返回和上面文法变量一样的内容
console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第四行所设置的权重一致
console.log(speechRecognitionList[0].src); // 返回值应与语法变量的内容相同
console.log(speechRecognitionList[0].weight); // 应返回 1——与 addFromString 中设置的权重相同。
```

## 规范
Expand All @@ -39,6 +35,6 @@ console.log(speechRecognitionList[0].weight); // 应该返回 1 - 与上面第

{{Compat}}

## 相关链接
## 参见

- [Web Speech API](/zh-CN/docs/Web/API/Web_Speech_API)

0 comments on commit e464daa

Please sign in to comment.