Class AudioDataStream

  • All Implemented Interfaces:
    AutoCloseable

    public final class AudioDataStream
    extends Object
    implements 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 Detail

      • 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.
      • 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.
      • getStatus

        public StreamStatus getStatus()
        Get current status of the audio data stream.
        Returns:
        Current status.
      • 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.
      • 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<Void> 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.
      • getPosition

        public long getPosition()
        Get current position of the audio data stream.
        Returns:
        Current position.
      • setPosition

        public void setPosition​(long pos)
        Set current position of the audio data stream.
        Parameters:
        pos - Position to be set.
      • detachInput

        public void detachInput()
        Stops any more data from getting to the stream.
      • 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.
      • getImpl

        public SafeHandle getImpl()
        Returns the audio data stream implementation.
        Returns:
        The implementation of the stream.
      • close

        public void close()
        Dispose of associated resources.
        Specified by:
        close in interface AutoCloseable