Hello,
I am facing some issues with a sample code which works on
emulator but not on an android device. The sample code does voice
recording and then plays the same. On emulator it works fine, though
there is some delay / gap in speaking and playing. But on the device
the only thing I could hear is loud noise but not my voice.
The app has two threads, one for the UI and the other for record and
playback. Please note that the record and playback are in the same
thread.
Also I see
The code looks something like as shown below. Any suggestions about
why there is a difference in playback on emulator vs device?
Thanks in advance,
Divkis
-----------------------------------------------------------------------------
nativeSampleRate = 8000;
AudioManager am = (AudioManager)
getSystemService(Context.AUDIO_SERVICE);
int actualBufferSize = 4096*8;
int capacity = 0;
int bufferSize = AudioTrack.getMinBufferSize(nativeSampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
AudioTrack atrack = new AudioTrack( AudioManager.STREAM_MUSIC,
nativeSampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
actualBufferSize,
AudioTrack.MODE_STREAM);
capacity = AudioRecord.getMinBufferSize(nativeSampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
byte[] buffer = new byte[actualBufferSize];
AudioRecord arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
nativeSampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
actualBufferSize);
am.setRouting(AudioManager.MODE_NORMAL,
AudioManager.ROUTE_EARPIECE,
AudioManager.ROUTE_ALL);
am.setSpeakerphoneOn(true);
am.setMicrophoneMute(false);
Log.d("SPEAKERPHONE", "Is speakerphoneon? : " +
am.isSpeakerphoneOn());
atrack.setPlaybackRate(nativeSampleRate);
arec.startRecording();
atrack.play();
while(true == isRecording)
{
int readSize = arec.read(buffer, 0, 320);
Log.v("Number of bytes read is ", " " + readSize);
int retVal = atrack.write(buffer, 0, readSize);
}
arec.stop();
atrack.stop();
}
--
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