다음을 통해 공유


Class SPXTranslationRecognizer

Declaration

@class SPXTranslationRecognizer : SPXRecognizer;

Description

Performs translation on the specified speech input, and gets transcribed and translated texts as result.

Methods

init:

Initializes a new instance of translation recognizer.

- (instancetype _Nullable)init:(SPXSpeechTranslationConfiguration * _Nonnull)translationConfiguration

Parameters

  • translationConfiguration - translation recognition configuration.

Returns

an instance of translation recognizer.

init:error:

Initializes a new instance of translation recognizer.

Added in version 1.6.0.

- (instancetype _Nullable)init:(SPXSpeechTranslationConfiguration * _Nonnull)translationConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • translationConfiguration - translation recognition configuration.
  • outError - error information.

Returns

an instance of translation recognizer.

initWithSpeechTranslationConfiguration:audioConfiguration:

Initializes a new instance of translation recognizer using the specified speech and audio configurations.

- (instancetype _Nullable)initWithSpeechTranslationConfiguration:(SPXSpeechTranslationConfiguration * _Nonnull)translationConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration

Parameters

  • translationConfiguration - speech translation recognition configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of translation recognizer.

initWithSpeechTranslationConfiguration:audioConfiguration:error:

Initializes a new instance of translation recognizer using the specified speech and audio configurations.

Added in version 1.6.0.

- (instancetype _Nullable)initWithSpeechTranslationConfiguration:(SPXSpeechTranslationConfiguration * _Nonnull)translationConfiguration
    audioConfiguration:(SPXAudioConfiguration * _Nonnull)audioConfiguration
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • translationConfiguration - speech translation recognition configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of translation recognizer.

initWithEmbeddedSpeechConfiguration:

Initializes a new instance of translation recognizer.

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

Parameters

  • embeddedSpeechConfiguration - embedded speech configuration.

Returns

an instance of translation recognizer.

initWithEmbeddedSpeechConfiguration:error:

Initializes a new instance of translation recognizer.

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

Parameters

  • embeddedSpeechConfiguration - embedded speech configuration.
  • outError - error information.

Returns

an instance of translation recognizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:

Initializes a new instance of translation recognizer using the specified speech and audio configurations.

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

Parameters

  • embeddedSpeechConfiguration - embedded speech configuration.
  • audioConfiguration - audio configuration.

Returns

an instance of translation recognizer.

initWithEmbeddedSpeechConfiguration:audioConfiguration:error:

Initializes a new instance of translation recognizer using the specified speech and audio configurations.

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

Parameters

  • embeddedSpeechConfiguration - embedded speech configuration.
  • audioConfiguration - audio configuration.
  • outError - error information.

Returns

an instance of translation recognizer.

recognizeOnce

Starts speech translation, 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 recognizeOnce() 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.

- (SPXTranslationRecognitionResult * _Nonnull)recognizeOnce

Returns

the result of translation.

recognizeOnce:

Starts speech translation, 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 recognizeOnce() 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.

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

Parameters

  • outError - error information.

Returns

the result of translation.

recognizeOnceAsync:

Starts translation, 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)(SPXTranslationRecognitionResult * _Nonnull))resultReceivedHandler

Parameters

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

recognizeOnceAsync:error:

Starts translation, 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)(SPXTranslationRecognitionResult * _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 translation on a continuous audio stream, until stopContinuousRecognition() is called. The user must subscribe to events to receive translation results.

- (void)startContinuousRecognition

startContinuousRecognition:

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

Added in version 1.6.0.

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

Parameters

  • outError - error information.

stopContinuousRecognition

Stops continuous translation.

- (void)stopContinuousRecognition

stopContinuousRecognition:

Stops continuous translation.

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, TranslationRecognizer 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, TranslationRecognizer 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, TranslationRecognizer 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:(SPXTranslationRecognitionAsyncCompletionHandler _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, TranslationRecognizer 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:(SPXTranslationRecognitionAsyncCompletionHandler _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:(SPXTranslationRecognitionAsyncCompletionHandler _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:(SPXTranslationRecognitionAsyncCompletionHandler _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:(SPXTranslationRecognitionEventHandler _Nonnull)eventHandler

addRecognizingEventHandler:

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

- (void)addRecognizingEventHandler:(SPXTranslationRecognitionEventHandler _Nonnull)eventHandler

addSynthesizingEventHandler:

Subscribes to the Synthesizing event which indicates that a synthesis voice output has been received.

- (void)addSynthesizingEventHandler:(SPXTranslationSynthesisEventHandler _Nonnull)eventHandler

addCanceledEventHandler:

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

- (void)addCanceledEventHandler:(SPXTranslationRecognitionCanceledEventHandler _Nonnull)eventHandler

addTargetLanguage:

Adds a target language for translation.

Added in version 1.7.0.

- (void)addTargetLanguage:(NSString * _Nonnull)lang

Parameters

  • lang - the language identifier in BCP-47 format.

removeTargetLanguage:

Removes a target language for translation.

Added in version 1.7.0.

- (void)removeTargetLanguage:(NSString * _Nonnull)lang

Parameters

  • lang - the language identifier in BCP-47 format.

Properties

authorizationToken

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

Authorization token used to communicate with the translation 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.

targetLanguages

@property (readonly, copy, nonatomic) NSArray * _Nonnull targetLanguages;

All target languages that have been configured for translation.

Added in version 1.7.0.