SpeechRecognitionErrorEvent: error 属性
SpeechRecognitionErrorEvent 接口中只读的 error 属性返回引发错误的类型。
值
一个表示错误类型的枚举值。可能的值包括:
- 已中止
- 
语音输入以某种方式被中止,可能是由于用户代理的特定行为,例如用户可以按下的取消语音输入的按钮。 
- audio-capture
- 
音频捕获失败。 
- bad-grammar已弃用 非标准
- 
语音识别语法或语义标签出现错误,或者选择的语法格式或语义标签格式不受支持。 注意:此错误已不再是 Web Speech API 规范的一部分;语法概念已从 Web Speech API 中移除。相关的特性仍然保留在规范中,并且仍然被支持的浏览器为了向后兼容而识别,但它们对语音识别服务没有影响。 
- language-not-supported
- 
用户代理不支持 SpeechRecognition对象中的lang属性指定的语言。支持的语言集取决于浏览器,并且无法从前端代码中以编程方式确定用户浏览器支持哪些语言用于语音识别。
- network
- 
完成识别所需的网络通信失败。 
- no-speech
- 
未检测到语音。 
- not-allowed
- 
出于安全、隐私或用户偏好的原因,用户代理不允许任何语音输入发生。 
- phrases-not-supported
- service-not-allowed
- 
用户代理不允许请求的语音识别服务,原因可能是用户代理不支持该服务,或者出于安全、隐私或用户偏好的原因。在这种情况下,它将允许使用另一个更合适的语音识别服务。 
示例
js
const recognition = new SpeechRecognition();
recognition.onerror = (event) => {
  console.log(`Speech recognition error detected: ${event.error}`);
  console.log(`Additional information: ${event.message}`);
};
规范
| 规范 | 
|---|
| Web Speech API # dom-speechrecognitionerrorevent-error | 
浏览器兼容性
加载中…