AudioDataStream Class

  • java.lang.Object
    • com.microsoft.cognitiveservices.speech.AudioDataStream

Implements

java.lang.AutoCloseable

public final class AudioDataStream
implements java.lang.AutoCloseable

Represents audio data stream used for operating audio data as a stream. Note: close() must be called in order to release underlying resources held by the object. Added in version 1.7.0

Method Summary

Modifier and Type Method and Description
boolean canReadData(long bytesRequested)

Check whether the stream has enough data to be read.

boolean canReadData(long pos, long bytesRequested)

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

void close()

Dispose of associated resources.

void detachInput()

Stops any more data from getting to the stream.

static AudioDataStream fromResult(KeywordRecognitionResult result)

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

static AudioDataStream fromResult(SpeechSynthesisResult result)

Creates a memory backed AudioDataStream from given speech synthesis result.

SafeHandle getImpl()

Returns the audio data stream implementation.

long getPosition()

Get current position of the audio data stream.

PropertyCollection getProperties()

The collection of properties and their values defined for this audio data stream.

StreamStatus getStatus()

Get current status of the audio data stream.

long readData(byte[] dataBuffer)

Reads the audio data specified by making an internal copy of the data.

long readData(long pos, byte[] dataBuffer)

Reads the audio data specified by making an internal copy of the data, starting from the specified position.

void saveToWavFile(String fileName)

Save the audio data to a file, synchronously.

java.util.concurrent.Future<java.lang.Void> saveToWavFileAsync(String fileName)

Save the audio data to a file, asynchronously.

void setPosition(long pos)

Set current position of the audio data stream.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

canReadData

public boolean canReadData(long bytesRequested)

Check whether the stream has enough data to be read.

Parameters:

bytesRequested - The requested data size in bytes.

Returns:

A bool indicating the result.

canReadData

public boolean canReadData(long pos, long bytesRequested)

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

Parameters:

pos - The position to start with.
bytesRequested - The requested data size in bytes.

Returns:

A bool indicating the result.

close

public void close()

Dispose of associated resources.

detachInput

public void detachInput()

Stops any more data from getting to the stream.

fromResult

public static AudioDataStream fromResult(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.

fromResult

public static AudioDataStream fromResult(SpeechSynthesisResult result)

Creates a memory backed AudioDataStream from given speech synthesis result.

Parameters:

result - The speech synthesis result.

Returns:

The audio data stream being created.

getImpl

public SafeHandle getImpl()

Returns the audio data stream implementation.

Returns:

The implementation of the stream.

getPosition

public long getPosition()

Get current position of the audio data stream.

Returns:

Current position.

getProperties

public PropertyCollection getProperties()

The collection of properties and their values defined for this audio data stream.

Returns:

The collection of properties and their values defined for this audio data stream.

getStatus

public StreamStatus getStatus()

Get current status of the audio data stream.

Returns:

Current status.

readData

public long readData(byte[] dataBuffer)

Reads the audio data specified by making an internal copy of the data. The maximal number of bytes to be read is determined by the size of dataBuffer. If there is no data immediately available, read() blocks until the next data becomes available.

Parameters:

dataBuffer - The audio buffer of which this function will make a copy to.

Returns:

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

readData

public long readData(long pos, byte[] dataBuffer)

Reads the audio data specified by making an internal copy of the data, starting from the specified position. The maximal number of bytes to be read is determined by the size of dataBuffer. If there is no data immediately available, read() blocks until the next data becomes available.

Parameters:

pos - The position to start with.
dataBuffer - The audio buffer of which this function will make a copy to.

Returns:

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

saveToWavFile

public void saveToWavFile(String fileName)

Save the audio data to a file, synchronously.

Parameters:

fileName - The file name with full path.

saveToWavFileAsync

public Future saveToWavFileAsync(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.

setPosition

public void setPosition(long pos)

Set current position of the audio data stream.

Parameters:

pos - Position to be set.

Applies to