语音识别:continuous 属性

continuous 属性是 SpeechRecognition 接口的一个属性,用于控制是否为每次识别返回连续结果,或只返回单个结果。

默认值为单个结果 (false.)

表示当前 SpeechRecognition 连续状态的布尔值。true 表示连续,false 表示非连续 (每次只返回单个结果)。

示例

此代码摘自我们的 语音颜色更改器 示例。

js
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 ;";
const recognition = new SpeechRecognition();
const speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.continuous = false;
recognition.lang = "en-US";
recognition.interimResults = false;
recognition.maxAlternatives = 1;

// ...

规范

规范
Web 语音 API
# dom-speechrecognition-continuous

浏览器兼容性

BCD 表格仅在启用 JavaScript 的浏览器中加载。

另请参阅