When switching between the emulator (which supports 8KHz) and a real
phone like the G1 (which supports 16KHz), I used the following code to
set up a valid AudioRecord object:
AudioRecord ar;
// Try to construct at 16KHz
ar = new AudioRecord(
MediaRecorder.AudioSource.MIC,
16000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
AUDIO_BUFFER_SIZE);
if (ar.getState() != AudioRecord.STATE_INITIALIZED) {
// Unable to set up at 16KHz, try at 8KHz
ar = new AudioRecord(
MediaRecorder.AudioSource.MIC,
8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
AUDIO_BUFFER_SIZE);
}
This seems to work just fine, and a 16KHz AudioRecord object is
instantiated on the G1, and a 8KHz object is instantiated on the
emulator.
However, on the Samsung Moment, which only supports 8KHz,
AudioRecord.getState() returns STATE_INITIALIZED when trying to
construct with 16KHz. This ends up causing recording to fail since
it's trying to record at 16KHz, even though the phone doesn't support
it. Also, I don't see any exceptions thrown when I try to wrap the
construction in a try-catch.
Does anyone know of a better way to detect 16KHz vs. 8KHz capabilities
on the device?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en