AudioDataStream Class

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

Generates an audio data stream from a speech synthesis result (type SpeechSynthesisResult) or a keyword recognition result (type KeywordRecognitionResult).

Inheritance
builtins.object
AudioDataStream

Constructor

AudioDataStream(result=None)

Parameters

result

The speech synthesis or keyword recognition result.

Methods

can_read_data

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

detach_input

Stop any more data from getting to the stream.

read_data

Reads the audio data from the audio data stream, starting from the specified position (if specified). The maximal number of bytes to be read is determined by the size of audio_buffer. If there is no data immediately available, read_data() blocks until the next data becomes available.

save_to_wav_file

Save the audio data to a file, synchronously.

save_to_wav_file_async

Save the audio data to a file, asynchronously.

can_read_data

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

can_read_data(requested_bytes: int, pos: typing.Union[int, NoneType] = None) -> bool

Parameters

requested_bytes
Required

The requested data size in bytes.

pos
default value: None

The position to start with. Will start from current position if this param is not given.

Returns

A bool indicating the result

detach_input

Stop any more data from getting to the stream.

detach_input()

read_data

Reads the audio data from the audio data stream, starting from the specified position (if specified). The maximal number of bytes to be read is determined by the size of audio_buffer. If there is no data immediately available, read_data() blocks until the next data becomes available.

read_data(audio_buffer: bytes, pos: typing.Union[int, NoneType] = None) -> int

Parameters

audio_buffer
Required

The buffer to receive the audio data.

pos
default value: None

The position to start with. Will start from current position if this param is not given.

Returns

The number of bytes filled, or 0 in case the stream hits its end and there is no more data available.

save_to_wav_file

Save the audio data to a file, synchronously.

save_to_wav_file(file_name: str)

Parameters

file_name
Required

Name of the file to be saved to

save_to_wav_file_async

Save the audio data to a file, asynchronously.

save_to_wav_file_async(file_name: str)

Parameters

file_name
Required

Name of the file to be saved to

Returns

An asynchronous operation representing the saving.

Attributes

position

Current position of the audio data stream.

status

Current status of the audio data stream.