Web Speech API

Web Speech API позволяет взаимодействовать с голосовыми интерфейсами в ваших веб приложениях. Web Speech API состоит из двух частей: SpeechSynthesis (Текст-в-Речь), и SpeechRecognition (Асинхронное распознавание речи)

Концепции и использование Web Speech

Web Speech API позволяет веб приложениям управлять голосовыми данными. Существует два компонента к этому API:

  • Распознавание голоса. Доступ обеспечивается через SpeechRecognition интерфейс, который в свою очередь обеспечивает возможность распознавать текст из входящего аудио потока (обычно через устройство распознавания речи в устройстве по умолчанию) и отвечать соответственно. Воспользовавшись конструктором интерфейса вы можете создать новый SpeechRecognition объект, у которого есть ряд событий для обнаружения начала речи через микрофон устройства. SpeechGrammar интерфейс предоставляет контейнер для определённого набора грамматики, которое ваше приложение должно использовать. Грамматика определяется с помощью JSpeech Grammar Format (JSGF.)
  • Доступ к синтезу речи осуществляется с помощью SpeechSynthesis (en-US) интерфейса, компонент text-to-speech позволяет приложениям прочесть свой текстовый контент (обычно через дефолтный синтезатор речи устройства). В SpeechSynthesisVoice (en-US) объектах есть различные типы голоса, и различным частям текста можно назначать SpeechSynthesisUtterance объекты. Можно начать воспроизведение передав их методу SpeechSynthesis.speak() (en-US).

Для большей информации по использованию этих фич, смотрите Using the Web Speech API.

Интерфейсы Web Speech API

Распознавание речи

SpeechRecognition

The controller interface for the recognition service; this also handles the SpeechRecognitionEvent (en-US) sent from the recognition service.

SpeechRecognitionAlternative (en-US)

Представляет одно слово которое было распознано службой распознавания голоса.

SpeechRecognitionError (en-US)

Представляет сообщения об ошибках из службы распознавания.

SpeechRecognitionEvent (en-US)

The event object for the result and nomatch events, and contains all the data associated with an interim or final speech recognition result.

SpeechGrammar

Слова или шаблоны слов которые мы хотим чтобы служба распознавания распознала.

SpeechGrammarList (en-US)

Представляет список объектов SpeechGrammar.

SpeechRecognitionResult (en-US)

Представляет одно распознанное совпадение, которое может содержать несколько объектов SpeechRecognitionAlternative (en-US).

SpeechRecognitionResultList (en-US)

Represents a list of SpeechRecognitionResult (en-US) objects, or a single one if results are being captured in continuous (en-US) mode.

Синтезирование речи

SpeechSynthesis (en-US)

The controller interface for the speech service; this can be used to retrieve information about the synthesis voices available on the device, start and pause speech, and other commands besides.

SpeechSynthesisErrorEvent (en-US)

Contains information about any errors that occur while processing SpeechSynthesisUtterance objects in the speech service.

SpeechSynthesisEvent (en-US)

Contains information about the current state of SpeechSynthesisUtterance objects that have been processed in the speech service.

SpeechSynthesisUtterance

Represents a speech request. It contains the content the speech service should read and information about how to read it (e.g. language, pitch and volume.)

SpeechSynthesisVoice (en-US)

Represents a voice that the system supports. Every SpeechSynthesisVoice has its own relative speech service including information about language, name and URI.

Window.speechSynthesis (en-US)

Specced out as part of a [NoInterfaceObject] interface called SpeechSynthesisGetter, and Implemented by the Window object, the speechSynthesis property provides access to the SpeechSynthesis (en-US) controller, and therefore the entry point to speech synthesis functionality.

Примеры

Web Speech API репозиторий на GitHub содержит примеры, показывающие распознавание и синтез речи.

Спецификации

Specification
Web Speech API

Совместимость с браузерами

api.SpeechRecognition

BCD tables only load in the browser

api.SpeechSynthesis

BCD tables only load in the browser

Смотрите также