Class AudioCaptureReader
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.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.digimarc.dms.readers.BaseReader
BaseReader.AudioSymbology, BaseReader.ImageDetectionType, BaseReader.ImageSymbology, BaseReader.ReaderError, BaseReader.ResultType, BaseReader.Symbology, BaseReader.UndefinedSymbology
-
Field Summary
Fields inherited from class com.digimarc.dms.readers.BaseReader
All_Audio_Readers, All_Barcode_1D_Readers, All_Barcode_Readers, All_Image_Readers
-
Method Summary
Modifier and TypeMethodDescriptionstatic AudioCaptureReader.Builder
Builder
(SdkSession sdkSession) Get Builder object for creating an AudioCaptureReader objectvoid
This method clears the internalPayloadCache
.int
Get the configured number of audio channels.int
Get the configured audio sample rate.void
Asynchronously process a buffer of audio data.void
release()
This method should be called when the reader is no longer needed.void
start()
Starts the audio capture service and begins reading audio data.void
stop()
Stops the audio service.Methods inherited from class com.digimarc.dms.readers.BaseReader
buildSymbologyMask, getReaderOptions, getSymbologies, setAllowPerformanceScheduling, setReaderOptions, setSymbologies
-
Method Details
-
Builder
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 classBaseCaptureReader
-
clearCache
public void clearCache()Description copied from class:BaseReader
This method clears the internalPayloadCache
.- Overrides:
clearCache
in classBaseReader
-
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
Asynchronously process a buffer of audio data. This method will return immediately and results will be delivered via theResultListener.onReaderResult(com.digimarc.dms.readers.ReaderResult, ResultType)
, orResultListener.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 indicatorByteBuffer.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.
-