public final class MicrophoneInput extends Object implements SpeechInput
This class wraps the android AudioRecord class for reading audio
samples from the microphone. It is assumed that the application has been
manifested for microphone input (android.permission.RECORD_AUDIO),
and that it has asked the user for microphone permissions via
android.support.v4.app.ActivityCompat.requestPermissions.
This class uses the configured sample rate and always reads single-chanel 16-bit PCM samples.
| Constructor and Description |
|---|
MicrophoneInput(android.media.AudioRecord audioRecord)
initializes a new microphone instance with an existing audio recorder;
useful for testing/mocking.
|
MicrophoneInput(SpeechConfig config)
initializes a new microphone instance and opens the audio recorder.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
releases the resources associated with the microphone.
|
void |
read(SpeechContext context,
ByteBuffer frame)
reads a frame from the microphone.
|
public MicrophoneInput(SpeechConfig config)
config - speech pipeline configurationpublic MicrophoneInput(android.media.AudioRecord audioRecord)
audioRecord - android audio recorder instance to attachpublic void close()
close in interface AutoCloseablepublic void read(SpeechContext context, ByteBuffer frame) throws AudioRecordError
read in interface SpeechInputcontext - the current speech contextframe - the frame buffer to fillAudioRecordError - if audio cannot be readCopyright © 2021. All rights reserved.