Freigeben über


Class SPXAudioDataStream

Declaration

@class SPXAudioDataStream : NSObject;

Description

Represents audio data stream used for operating audio data as a stream.

Added in version 1.7.0

Methods

initFromSynthesisResult:

Initializes an audio data stream from given speech synthesis result.

- (instancetype _Nullable)initFromSynthesisResult:(SPXSpeechSynthesisResult * _Nonnull)result

Parameters

  • result - the speech synthesis result.

Returns

an instance of audio data stream.

initFromSynthesisResult:error:

Initializes an audio data stream from given speech synthesis result.

- (instancetype _Nullable)initFromSynthesisResult:(SPXSpeechSynthesisResult * _Nonnull)result
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • result - the speech synthesis result.
  • outError - error information.

Returns

an instance of audio data stream.

initFromKeywordRecognitionResult:

Obtains the memory backed AudioDataStream associated with a given KeywordRecognition result.

- (instancetype _Nullable)initFromKeywordRecognitionResult:(SPXKeywordRecognitionResult * _Nonnull)result

Parameters

  • result - the keyword recognition result.

Returns

An audio stream with the input to the KeywordRecognizer starting from right before the Keyword.

initFromKeywordRecognitionResult:error:

Obtains the memory backed AudioDataStream associated with a given KeywordRecognition result.

- (instancetype _Nullable)initFromKeywordRecognitionResult:(SPXKeywordRecognitionResult * _Nonnull)result
    error:(NSError * _Nullable * _Nullable)outError

Parameters

  • result - the keyword recognition result.
  • outError - error information.

Returns

An audio stream with the input to the KeywordRecognizer starting from right before the Keyword.

getStatus

Get current status of the audio data stream.

- (SPXStreamStatus)getStatus

Returns

current status.

canReadData:

Check wheather the stream has enough data to be read.

- (BOOL)canReadData:(NSUInteger)bytesRequested

Parameters

  • bytesRequested - the request data size in bytes.

Returns

a bool indicating whether the stream has enough data to be read.

canReadDataFromPosition:bytesRequested:

Check whether the stream has enough data to be read, starting from the specified position.

- (BOOL)canReadDataFromPosition:(NSUInteger)pos bytesRequested:(NSUInteger)bytesRequested

Parameters

  • pos - the position counting from start of the stream.
  • bytesRequested - the request data size in bytes.

Returns

a bool indicating whether the stream has enough data to be read.

readData:length:

Reads a chunk of the audio data and fill it to given buffer.

- (NSUInteger)readData:(NSMutableData * _Nonnull)data length:(NSUInteger)length

Parameters

  • data - a buffer to receive read data.
  • length - length of the data to be received.

Returns

length of data filled to the buffer, 0 means end of stream.

readDataFromPosition:data:length:

Reads a chunk of the audio data and fill it to given buffer, starting from the specified position.

- (NSUInteger)readDataFromPosition:(NSUInteger)pos data:(NSMutableData * _Nonnull)data
    length:(NSUInteger)length

Parameters

  • pos - the position counting from start of the stream.
  • data - a buffer to receive read data.
  • length - length of the data to be received.

Returns

length of data filled to the buffer, 0 means end of stream.

saveToWavFile:

Save the audio data to a file.

- (void)saveToWavFile:(NSString * _Nonnull)fileName

Parameters

  • fileName - the file name with full path.

getPosition

Get current position of the audio data stream.

- (NSUInteger)getPosition

Returns

current position

setPosition:

Set current position of the audio data stream.

- (void)setPosition:(NSUInteger)pos

Parameters

  • pos - position to be set.

detachInput

Stops any more data from getting to the stream.

- (void)detachInput

detachInput:

Stops any more data from getting to the stream.

- (void)detachInput:(NSError * _Nullable * _Nullable)outError

Parameters

  • outError - error information.