SpeechRecognizer class

Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result.

Extends

Constructors

SpeechRecognizer(SpeechConfig, AudioConfig)

SpeechRecognizer constructor.

Properties

authorizationToken

Gets the authorization token used to communicate with the service. Gets/Sets the authorization token used to communicate with the service.

canceled

The event canceled signals that an error occurred during recognition.

endpointId

Gets the endpoint id of a customized speech model that is used for speech recognition.

internalData
outputFormat

Gets the output format of recognition.

properties

The collection of properties and their values defined for this SpeechRecognizer.

recognized

The event recognized signals that a final recognition result is received.

recognizing

The event recognizing signals that an intermediate recognition result is received.

sessionStarted

Defines event handler for session started events.

sessionStopped

Defines event handler for session stopped events.

speechEndDetected

Defines event handler for speech stopped events.

speechRecognitionLanguage

Gets the spoken language of recognition.

speechStartDetected

Defines event handler for speech started events.

telemetryEnabled

This method returns the current state of the telemetry setting.

Methods

close(() => void, (error: string) => void)

closes all external resources held by an instance of this class.

dispose(boolean)

Disposes any resources held by the object.

enableTelemetry(boolean)

This method globally enables or disables telemetry.

FromConfig(SpeechConfig, AutoDetectSourceLanguageConfig, AudioConfig)

SpeechRecognizer constructor.

recognizeOnceAsync((e: SpeechRecognitionResult) => void, (e: string) => void)

Starts speech recognition, and stops after the first utterance is recognized. The task returns the recognition text as result. Note: RecognizeOnceAsync() returns when the first utterance has been recognized, so it is suitable only for single shot recognition like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.

startContinuousRecognitionAsync(() => void, (e: string) => void)

Starts speech recognition, until stopContinuousRecognitionAsync() is called. User must subscribe to events to receive recognition results.

startKeywordRecognitionAsync(KeywordRecognitionModel, () => void, (e: string) => void)

Starts speech recognition with keyword spotting, until stopKeywordRecognitionAsync() is called. User must subscribe to events to receive recognition results. Note: Key word spotting functionality is only available on the Speech Devices SDK. This functionality is currently not included in the SDK itself.

stopContinuousRecognitionAsync(() => void, (e: string) => void)

Stops continuous speech recognition.

stopKeywordRecognitionAsync(() => void, (e: string) => void)

Stops continuous speech recognition. Note: Key word spotting functionality is only available on the Speech Devices SDK. This functionality is currently not included in the SDK itself.

Constructor Details

SpeechRecognizer(SpeechConfig, AudioConfig)

SpeechRecognizer constructor.

new SpeechRecognizer(speechConfig: SpeechConfig, audioConfig?: AudioConfig)

Parameters

speechConfig
SpeechConfig

an set of initial properties for this recognizer

audioConfig
AudioConfig

An optional audio configuration associated with the recognizer

Property Details

authorizationToken

Gets the authorization token used to communicate with the service. Gets/Sets the authorization token used to communicate with the service.

string authorizationToken

Property Value

string

Authorization token.

canceled

The event canceled signals that an error occurred during recognition.

public canceled: (sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void

Property Value

(sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void

endpointId

Gets the endpoint id of a customized speech model that is used for speech recognition.

string endpointId

Property Value

string

the endpoint id of a customized speech model that is used for speech recognition.

internalData

object internalData

Property Value

object

outputFormat

Gets the output format of recognition.

OutputFormat outputFormat

Property Value

The output format of recognition.

properties

The collection of properties and their values defined for this SpeechRecognizer.

PropertyCollection properties

Property Value

The collection of properties and their values defined for this SpeechRecognizer.

recognized

The event recognized signals that a final recognition result is received.

public recognized: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void

Property Value

(sender: Recognizer, event: SpeechRecognitionEventArgs) => void

recognizing

The event recognizing signals that an intermediate recognition result is received.

public recognizing: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void

Property Value

(sender: Recognizer, event: SpeechRecognitionEventArgs) => void

sessionStarted

Defines event handler for session started events.

public sessionStarted: (sender: Recognizer, event: SessionEventArgs) => void

Property Value

(sender: Recognizer, event: SessionEventArgs) => void

sessionStopped

Defines event handler for session stopped events.

public sessionStopped: (sender: Recognizer, event: SessionEventArgs) => void

Property Value

(sender: Recognizer, event: SessionEventArgs) => void

speechEndDetected

Defines event handler for speech stopped events.

public speechEndDetected: (sender: Recognizer, event: RecognitionEventArgs) => void

Property Value

(sender: Recognizer, event: RecognitionEventArgs) => void

speechRecognitionLanguage

Gets the spoken language of recognition.

string speechRecognitionLanguage

Property Value

string

The spoken language of recognition.

speechStartDetected

Defines event handler for speech started events.

public speechStartDetected: (sender: Recognizer, event: RecognitionEventArgs) => void

Property Value

(sender: Recognizer, event: RecognitionEventArgs) => void

telemetryEnabled

This method returns the current state of the telemetry setting.

static boolean telemetryEnabled

Property Value

boolean

true if the telemetry is enabled, false otherwise.

Method Details

close(() => void, (error: string) => void)

closes all external resources held by an instance of this class.

function close(cb?: () => void, errorCb?: (error: string) => void)

Parameters

cb

() => void

errorCb

(error: string) => void

dispose(boolean)

Disposes any resources held by the object.

function dispose(disposing: boolean)

Parameters

disposing

boolean

true if disposing the object.

Returns

Promise<void>

enableTelemetry(boolean)

This method globally enables or disables telemetry.

static function enableTelemetry(enabled: boolean)

Parameters

enabled

boolean

Global setting for telemetry collection. If set to true, telemetry information like microphone errors, recognition errors are collected and sent to Microsoft. If set to false, no telemetry is sent to Microsoft.

FromConfig(SpeechConfig, AutoDetectSourceLanguageConfig, AudioConfig)

SpeechRecognizer constructor.

static function FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig)

Parameters

speechConfig
SpeechConfig

an set of initial properties for this recognizer

autoDetectSourceLanguageConfig
AutoDetectSourceLanguageConfig

An source language detection configuration associated with the recognizer

audioConfig
AudioConfig

An optional audio configuration associated with the recognizer

Returns

recognizeOnceAsync((e: SpeechRecognitionResult) => void, (e: string) => void)

Starts speech recognition, and stops after the first utterance is recognized. The task returns the recognition text as result. Note: RecognizeOnceAsync() returns when the first utterance has been recognized, so it is suitable only for single shot recognition like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.

function recognizeOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void)

Parameters

cb

(e: SpeechRecognitionResult) => void

Callback that received the SpeechRecognitionResult.

err

(e: string) => void

Callback invoked in case of an error.

startContinuousRecognitionAsync(() => void, (e: string) => void)

Starts speech recognition, until stopContinuousRecognitionAsync() is called. User must subscribe to events to receive recognition results.

function startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void)

Parameters

cb

() => void

Callback invoked once the recognition has started.

err

(e: string) => void

Callback invoked in case of an error.

startKeywordRecognitionAsync(KeywordRecognitionModel, () => void, (e: string) => void)

Starts speech recognition with keyword spotting, until stopKeywordRecognitionAsync() is called. User must subscribe to events to receive recognition results. Note: Key word spotting functionality is only available on the Speech Devices SDK. This functionality is currently not included in the SDK itself.

function startKeywordRecognitionAsync(model: KeywordRecognitionModel, cb?: () => void, err?: (e: string) => void)

Parameters

model
KeywordRecognitionModel

The keyword recognition model that specifies the keyword to be recognized.

cb

() => void

Callback invoked once the recognition has started.

err

(e: string) => void

Callback invoked in case of an error.

stopContinuousRecognitionAsync(() => void, (e: string) => void)

Stops continuous speech recognition.

function stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void)

Parameters

cb

() => void

Callback invoked once the recognition has stopped.

err

(e: string) => void

Callback invoked in case of an error.

stopKeywordRecognitionAsync(() => void, (e: string) => void)

Stops continuous speech recognition. Note: Key word spotting functionality is only available on the Speech Devices SDK. This functionality is currently not included in the SDK itself.

function stopKeywordRecognitionAsync(cb?: () => void, err?: (e: string) => void)

Parameters

cb

() => void

Callback invoked once the recognition has stopped.

err

(e: string) => void

Callback invoked in case of an error.