class AudioDataStream

class AudioDataStream
  : public std::enable_shared_from_this< AudioDataStream >

Represents audio data stream used for operating audio data as a stream. Added in version 1.4.0

Members

Properties

Syntax: public const PropertyCollection & Properties;

Collection of additional SpeechSynthesisResult properties.

~AudioDataStream

Syntax: public inline ~AudioDataStream ( );

Destroy the instance.

GetStatus

Syntax: public inline StreamStatus GetStatus ( );

Get current status of the audio data stream.

Returns

Current status

CanReadData

Syntax: public inline bool CanReadData ( uint32_t bytesRequested );

Check whether the stream has enough data to be read.

Parameters

  • bytesRequested The requested data size in bytes.

Returns

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

CanReadData

Syntax: public inline bool CanReadData ( uint32_t pos , uint32_t bytesRequested );

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

Parameters

  • pos The position counting from start of the stream.

  • bytesRequested The requested data size in bytes.

Returns

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

ReadData

Syntax: public inline uint32_t ReadData ( uint8_t * buffer , uint32_t bufferSize );

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

Parameters

  • buffer A buffer to receive read data.

  • bufferSize Size of the buffer.

Returns

Size of data filled to the buffer, 0 means end of stream

ReadData

Syntax: public inline uint32_t ReadData ( uint32_t pos , uint8_t * buffer , uint32_t bufferSize );

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

Parameters

  • pos The position counting from start of the stream.

  • buffer A buffer to receive read data.

  • bufferSize Size of the buffer.

Returns

Size of data filled to the buffer, 0 means end of stream

SaveToWavFile

Syntax: public inline void SaveToWavFile ( const std::string & fileName );

Save the audio data to a file, synchronously.

Parameters

  • fileName The file name with full path.

SaveToWavFileAsync

Syntax: public inline std::future< void > SaveToWavFileAsync ( const std::string & fileName );

Save the audio data to a file, asynchronously.

Parameters

  • fileName The file name with full path.

Returns

An asynchronous operation representing the saving.

GetPosition

Syntax: public inline uint32_t GetPosition ( );

Get current position of the audio data stream.

Returns

Current position

SetPosition

Syntax: public inline void SetPosition ( uint32_t pos );

Set current position of the audio data stream.

Parameters

  • pos Position to be set.

DetachInput

Syntax: public inline void DetachInput ( );

Stops any more data from getting to the stream.

operator SPXAUDIOSTREAMHANDLE

Syntax: public inline explicit operator SPXAUDIOSTREAMHANDLE ( );

Explicit conversion operator.

Returns

A handle.

FromResult

Syntax: public inline static std::shared_ptr< AudioDataStream > FromResult ( std::shared_ptr< SpeechSynthesisResult > result );

Creates a memory backed AudioDataStream from given speech synthesis result.

Parameters

  • result The speech synthesis result.

Returns

A shared pointer to AudioDataStream

FromResult

Syntax: public inline static std::shared_ptr< AudioDataStream > FromResult ( std::shared_ptr< KeywordRecognitionResult > result );

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

Parameters

  • result The keyword recognition result.

Returns

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