Web Speech API
The SpeechRecognitionEvent() constructor creates a new
SpeechRecognitionEvent object instance.
Syntax
new SpeechRecognitionEvent(type, init)
Parameters
type- : A string containing the name of the event. This will be
resultornomatch, depending on the event that created the instance.
- : A string containing the name of the event. This will be
init- : An initialization object that contains the following properties:
resultIndex- : A number representing the lowest index value result in the SpeechRecognitionResultList instance that has actually changed.
results- : A SpeechRecognitionResultList object representing all the speech recognition results returned in the associated event.
- : An initialization object that contains the following properties:
Examples
You would be unlikely to construct a SpeechRecognitionEvent instance manually. Such instances are available as event objects inside result and nomatch event handler functions.
For example:
recognition.addEventListener("result", (event) => {
const color = event.results[0][0].transcript;
diagnostic.textContent = `Result received: ${color}.`;
bg.style.backgroundColor = color;
console.log(`Confidence: ${event.results[0][0].confidence}`);
});
Specifications
Browser compatibility
See also
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
