Freigeben über


Class SPXSpeechRecognizer

Declaration

@class SPXSpeechRecognizer : SPXRecognizer;

Description

Performs speech recognition on the specified audio input, and gets transcribed text as result.

Methods

init:

Initializes a new instance of speech recognizer.

- (instancetype _Nullable)init:(SPXSpeechConfiguration * _Nonnull)speechConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.

Returns

an instance of speech recognizer.

init:error:

Initializes a new instance of speech recognizer.

Added in version 1.6.0.

- (instancetype _Nullable)init:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:

Initializes a new instance of speech recognizer.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration

Parameters

  • speechConfiguration - embedded speech recognition configuration.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:error:

Initializes a new instance of speech recognizer.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:audioConfiguration:

Initializes a new instance of speech recognizer using the specified audio config.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified audio config.

Added in version 1.6.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:

Initializes a new instance of speech recognizer using the specified audio config.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified audio config.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:language:

Initializes a new instance of speech recognizer using the specified source language.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    language:(NSString * _Nonnull)language

Parameters

  • speechConfiguration - speech recognition configuration.
  • language - source language.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:language:error:

Initializes a new instance of speech recognizer using the specified source language.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    language:(NSString * _Nonnull)language error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • language - source language.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:language:audioConfiguration:

Initializes a new instance of speech recognizer using the specified source language and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    language:(NSString * _Nonnull)language
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • language - source language.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:language:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified source language and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    language:(NSString * _Nonnull)language
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • language - source language.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:sourceLanguageConfiguration:

Initializes a new instance of speech recognizer using the specified source language configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    sourceLanguageConfiguration:(SPXSourceLanguageConfiguration * _Nonnull)sourceLanguageConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • sourceLanguageConfiguration - the source language configuration.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:sourceLanguageConfiguration:error:

Initializes a new instance of speech recognizer using the specified source language configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    sourceLanguageConfiguration:(SPXSourceLanguageConfiguration * _Nonnull)sourceLanguageConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • sourceLanguageConfiguration - the source language configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:sourceLanguageConfiguration:audioConfiguration:

Initializes a new instance of speech recognizer using the specified source language configuration and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    sourceLanguageConfiguration:(SPXSourceLanguageConfiguration * _Nonnull)sourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • sourceLanguageConfiguration - the source language configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:sourceLanguageConfiguration:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified source language configuration and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    sourceLanguageConfiguration:(SPXSourceLanguageConfiguration * _Nonnull)sourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • sourceLanguageConfiguration - the source language configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:error:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:autoDetectSourceLanguageConfiguration:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:autoDetectSourceLanguageConfiguration:error:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection and audio configuration.

Added in version 1.12.0.

- (instancetype _Nullable)initWithSpeechConfiguration:(SPXSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection and audio configuration.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.

Returns

an instance of speech recognizer.

initWithEmbeddedSpeechConfiguration:autoDetectSourceLanguageConfiguration:audioConfiguration:error:

Initializes a new instance of speech recognizer using the specified configuration for auto language detection and audio configuration.

- (instancetype _Nullable)initWithEmbeddedSpeechConfiguration:(SPXEmbeddedSpeechConfiguration * _Nonnull)speechConfiguration
    autoDetectSourceLanguageConfiguration:(SPXAutoDetectSourceLanguageConfiguration * _Nonnull)autoDetectSourceLanguageConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • speechConfiguration - embedded speech recognition configuration.
  • autoDetectSourceLanguageConfiguration - the configuration for auto language detection.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of speech recognizer.

recognizeOnce

Starts speech recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result.

Note: Since recognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use startContinuousRecognition() instead.

- (SPXSpeechRecognitionResult * _Nonnull)recognizeOnce

Returns

the result of speech recognition.

recognizeOnce:

Starts speech recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result.

Note: Since recognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use startContinuousRecognition() instead.

Added in version 1.6.0.

- (SPXSpeechRecognitionResult * _Nullable)recognizeOnce:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

Returns

the result of speech recognition.

recognizeOnceAsync:

Starts speech recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result.

Note: Since recognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use startContinuousRecognition() instead.

- (void)recognizeOnceAsync:(void (^ _Nonnull)(SPXSpeechRecognitionResult * _Nonnull))resultReceivedHandler

Parameters

  • resultReceivedHandler - the block function to be called when the first utterance has been recognized.

recognizeOnceAsync:error:

Starts speech recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result.

Note: Since recognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use startContinuousRecognition() instead.

Added in version 1.6.0.

- (BOOL)recognizeOnceAsync:(void (^ _Nonnull)(SPXSpeechRecognitionResult * _Nonnull))resultReceivedHandler
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • resultReceivedHandler - the block function to be called when the first utterance has been recognized.
  • outError - error information.

startContinuousRecognition

Starts speech recognition on a continuous audio stream, until stopContinuousRecognition() is called. User must subscribe to events to receive recognition results.

- (void)startContinuousRecognition

startContinuousRecognition:

Starts speech recognition on a continuous audio stream, until stopContinuousRecognition() is called. User must subscribe to events to receive recognition results.

Added in version 1.6.0.

- (BOOL)startContinuousRecognition:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

stopContinuousRecognition

Stops continuous speech recognition.

- (void)stopContinuousRecognition

stopContinuousRecognition:

Stops continuous speech recognition.

Added in version 1.6.0.

- (BOOL)stopContinuousRecognition:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

startKeywordRecognition:error:

Begins a speech-to-text interaction with this recognizer using a keyword. This interaction will use the provided keyword model to listen for a keyword indefinitely, during which audio is not sent to the speech service and all processing is performed locally. When a keyword is recognized, SpeechRecognizer will automatically connect to the speech service and begin sending audio data from just before the keyword. When received, speech-to-text results may be processed by the provided result handler or retrieved via a subscription to the recognized event.

- (BOOL)startKeywordRecognition:(SPXKeywordRecognitionModel * _Nonnull)keywordModel
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • keywordModel - the keyword recognition model.
  • outError - error information.

Returns

a value indicating whether the requested keyword recognition successfully started. If NO, outError may contain additional information.

startKeywordRecognition:

Begins a speech-to-text interaction with this recognizer using a keyword. This interaction will use the provided keyword model to listen for a keyword indefinitely, during which audio is not sent to the speech service and all processing is performed locally. When a keyword is recognized, SpeechRecognizer will automatically connect to the speech service and begin sending audio data from just before the keyword. When received, speech-to-text results may be processed by the provided result handler or retrieved via a subscription to the recognized event.

- (void)startKeywordRecognition:(SPXKeywordRecognitionModel * _Nonnull)keywordModel

Parameters

  • keywordModel - the keyword recognition model.

startKeywordRecognitionAsync:completionHandler:error:

Asynchronously begins a speech-to-text interaction with this recognizer and immediately returns execution to the calling thread. This interaction will use the provided keyword model to listen for a keyword indefinitely, during which audio is not sent to the speech service and all processing is performed locally. When a keyword is recognized, SpeechRecognizer will automatically connect to the speech service and begin sending audio data from just before the keyword. When received, speech-to-text results may be processed by the provided result handler or retrieved via a subscription to the recognized event.

- (BOOL)startKeywordRecognitionAsync:(SPXKeywordRecognitionModel * _Nonnull)keywordModel
    completionHandler:(SPXSpeechRecognitionAsyncCompletionHandler _Nonnull)completionHandler
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • keywordModel - the keyword recognition model.
  • completionHandler - the handler function called when keyword recognition has started.
  • outError - error information.

Returns

a value indicating whether the request to start keyword recognition was received successfully. If NO, additional information may available in outError.

startKeywordRecognitionAsync:completionHandler:

Asynchronously begins a speech-to-text interaction with this recognizer and immediately returns execution to the calling thread. This interaction will use the provided keyword model to listen for a keyword indefinitely, during which audio is not sent to the speech service and all processing is performed locally. When a keyword is recognized, SpeechRecognizer will automatically connect to the speech service and begin sending audio data from just before the keyword. When received, speech-to-text results may be processed by the provided result handler or retrieved via a subscription to the recognized event.

- (void)startKeywordRecognitionAsync:(SPXKeywordRecognitionModel * _Nonnull)keywordModel
    completionHandler:(SPXSpeechRecognitionAsyncCompletionHandler _Nonnull)completionHandler

Parameters

  • keywordModel - the keyword recognition model.
  • completionHandler - the handler function called when keyword recognition has started.

stopKeywordRecognition:

Stops any active keyword recognition.

- (BOOL)stopKeywordRecognition:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.

Returns

a value indicating whether keyword recognition was stopped successfully. If NO, additional information may be available in outError.

stopKeywordRecognition

Stops any active keyword recognition.

- (void)stopKeywordRecognition

stopKeywordRecognitionAsync:error:

Stops any active keyword recognition.

- (BOOL)stopKeywordRecognitionAsync:(SPXSpeechRecognitionAsyncCompletionHandler _Nonnull)completionHandler
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • completionHandler - the handler function called when keyword recognition has stopped.
  • outError - error information.

Returns

a value indicating whether the request to stop was received successfully. If NO, additional error information may be available in outError.

stopKeywordRecognitionAsync:

Stops any active keyword recognition.

- (void)stopKeywordRecognitionAsync:(SPXSpeechRecognitionAsyncCompletionHandler _Nonnull)completionHandler

Parameters

  • completionHandler - the handler function called when keyword recognition has stopped.

addRecognizedEventHandler:

Subscribes to the Recognized event which indicates that a final result has been recognized.

- (void)addRecognizedEventHandler:(SPXSpeechRecognitionEventHandler _Nonnull)eventHandler

addRecognizingEventHandler:

Subscribes to the Recognizing event which indicates that an intermediate result has been recognized.

- (void)addRecognizingEventHandler:(SPXSpeechRecognitionEventHandler _Nonnull)eventHandler

addCanceledEventHandler:

Subscribes to the Canceled event which indicates that an error occurred during recognition.

- (void)addCanceledEventHandler:(SPXSpeechRecognitionCanceledEventHandler _Nonnull)eventHandler

Properties

authorizationToken

@property (readwrite, copy, nonatomic) NSString * _Nullable authorizationToken;

Authorization token used to communicate with the speech recognition service.

Note: The caller needs to ensure that the authorization token is valid. Before the authorization token expires, the caller needs to refresh it by calling this setter with a new valid token. Otherwise, the recognizer will encounter errors during recognition.

endpointId

@property (readonly, copy, nonatomic) NSString * _Nullable endpointId;

Endpoint ID of a customized speech model that is used for speech recognition.