Home > Web Front-end > JS Tutorial > body text

A brief analysis of how to use JavaScript for speech recognition

高洛峰
Release: 2016-12-08 16:13:44
Original
3272 people have browsed it

1. Basic Usage

var recognition = new webkitSpeechRecognition();
recognition.onresult = function(event) {
 console.log(event)
}
recognition.start();
Copy after login

The operation here will actually enable the user authorization page to turn on the microphone. If the user allows it, the user can start talking. If you stop talking, the onresult registration time will be triggered, and Will return the captured audio as a JavaScript object.

2. Response flow

You need to wait for the user to be ready for the conversation and know that the conversation is over;

var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.onresult = function(event) {
 console.log(event)
}
recognition.start();
Copy after login

A brief analysis of how to use JavaScript for speech recognition

This way you can render the result in advance when the user starts to speak.

You can automatically select the recognized language, and the default is the local language.

Three, x-webkit-speech

Webkit-based browser supports voice input

<input type="text" x-webkit-speech />
Copy after login

It will recognize audio and convert it into text

Four. Security

Browser under http protocol The user will be reminded to confirm the voice operation every time, but the https page does not have such a troublesome operation.
JavaScript context, the entire page, can access the captured audio.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template