Class AudioCaptureReader


public class AudioCaptureReader extends BaseCaptureReader

This class provides asynchronous audio reading. Internally, an AudioCaptureReader instance creates an AudioHelper, that samples audio from the device's microphone and passes it to the processAudioSamples(java.nio.ByteBuffer) function. Results are delivered asynchronously by the ResultListener interface.

Given the real-time nature of captured audio this class will generally be given higher priority than image readers. This is because audio payloads are decoded by capturing and reading a succession of audio frames in order to decode a payload, while image frames may each be read on its own without needing the previous frame. If audio packets are lost within a capture session (this can happen if the audio reader gets backed up and runs out of audio buffer space), the read process has to restart and any audio decodes will be delayed by at least a couple of seconds.

  • Method Details

    • Builder

      @NonNull public static AudioCaptureReader.Builder Builder(SdkSession sdkSession)
      Get Builder object for creating an AudioCaptureReader object
      Parameters:
      sdkSession - SdkSession object initialized with a valid license key.
      Returns:
      Builder
    • start

      public void start()
      Starts the audio capture service and begins reading audio data. This should be called in your application's onResume method. The call is asynchronous, and audio data will be flowing once the has finished initialization.
    • stop

      public void stop()
      Stops the audio service. This should be called in your application's onPause method.
    • release

      public void release()
      Description copied from class: BaseReader
      This method should be called when the reader is no longer needed. Failure to call this method may result in objects remaining in memory beyond their useful lifespan.
      Overrides:
      release in class BaseCaptureReader
    • clearCache

      public void clearCache()
      Description copied from class: BaseReader
      This method clears the internal PayloadCache.
      Overrides:
      clearCache in class BaseReader
    • createDetectors

      protected void createDetectors() throws ReaderException
      Overrides:
      createDetectors in class BaseReader
      Throws:
      ReaderException
    • getSampleRate

      public int getSampleRate()
      Get the configured audio sample rate.
      Returns:
      Returns the audio sample rate this reader is configured for.
    • getNumChannels

      public int getNumChannels()
      Get the configured number of audio channels.
      Returns:
      Returns the number of audio channels this reader is configured for.
    • processAudioSamples

      public void processAudioSamples(@NonNull ByteBuffer data) throws ReaderException
      Asynchronously process a buffer of audio data. This method will return immediately and results will be delivered via the ResultListener.onReaderResult(com.digimarc.dms.readers.ReaderResult, ResultType), or ResultListener.onError(com.digimarc.dms.readers.BaseReader.ReaderError, com.digimarc.dms.readers.BaseReader.ResultType) listener interfaces.
      Parameters:
      data - Android ByteBuffer of audio data. The reader determines how much data is available by referring to the buffer's position indicator ByteBuffer.position(int). The AudioHelper class does this automatically, but if you are writing your own audio capture code make sure that the position is set to the first byte beyond the end of the audio data.
      Throws:
      ReaderException - Throws an exception if an error occurs in processing. This may occur if the samples don't match the size of the input data or if the audio configuration parameters don't match the data buffer.