Hi Tom, Yes, I did get it figured out. Here's a writeup I posted on my blog. http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/
-Ben <http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/> Hi there, Did you ever have any luck with this AudioRecord API? There are questions on SO as well, but noone seems to give a clear answer: http://stackoverflow.com/questions/4525206/android-audiorecord-class-process-live-mic-audio-quickly-set-up-callback-funct http://stackoverflow.com/questions/4707994/android-audiorecord-questions/ Regards, Tom <http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/> On Tue, May 19, 2009 at 3:30 PM, Keith Wiley <kbwi...@gmail.com> wrote: > > I would like to do this too, and I also took the OP's approach. I > can't actually get AudioRecord's ctor to set the state to > STATE_INITIALIZED, but that's a separate issue. I'm trying to > understand the correct code structure. You say we shouldn't use the > position-based callback, but instead should making a blocking call to > read(). Can you explain why that is? For what application is the > callback approach recommended instead of the blocking read() approach? > > Also, regardless of whether we *should* call read(), do you know why > the OP said his callback was not being called? What's wrong with the > code he provided? > > On May 19, 2:54 pm, Dave Sparks <davidspa...@android.com> wrote: > > You probably don't need the callback interface. The read() will block > > until the buffer is full. > > > > If you are getting buffer overflows, you are probably spending too > > much time in your doSomething() call. > > > > On May 19, 11:59 am, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > > > Thanks for the response. I'm still foggy on the API usage though. I > > > basically want to listen to the mic and continually process the > > > incoming audio. Should I be using the OnRecordPositionUpdateListener > > > at all? > > > > > Or should it look something like: > > > recorder.startRecording() > > > while(recorder.read(buffer) > 0) { > > > doSomething(buffer) > > > > > } > > > > > When I've done the latter I get buffer overflow exceptions. > > > > > On May 15, 3:51 pm, Dave Sparks <davidspa...@android.com> wrote: > > > > > > You need to call the read() method. > > > > > > On May 15, 3:15 pm, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > > > > > Any ideas? > > > > > > > Thanks, > > > > > Ben > > > > > > > On May 15, 1:02 am, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > > > > > > Hi, > > > > > > I'm trying to figure out how to use theAudioRecordclass. I > created > > > > > > a callback with a logging message, but don't ever see it called. > Do > > > > > > you see anything wrong with what I'm doing? Do you have an > example of > > > > > > how to use the API? > > > > > > > > Thanks, > > > > > > Ben > > > > > > > > import android.media.AudioFormat; > > > > > > import android.media.AudioRecord; > > > > > > import android.media.MediaRecorder; > > > > > > import android.util.Log; > > > > > > > > public class AudioListener { > > > > > > > > public static final int DEFAULT_SAMPLE_RATE = 8000; > > > > > > private static final int DEFAULT_BUFFER_SIZE = 4096; > > > > > > private static final int CALLBACK_PERIOD = 4000; // 500 msec > > > > > > (sample rate / callback period) > > > > > > private finalAudioRecordrecorder; > > > > > > > > public AudioListener() { > > > > > > this(DEFAULT_SAMPLE_RATE); > > > > > > } > > > > > > > > private AudioListener(int sampleRate) { > > > > > > recorder = newAudioRecord(MediaRecorder.AudioSource.DEFAULT, > > > > > > sampleRate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, > > > > > > AudioFormat.ENCODING_DEFAULT, DEFAULT_BUFFER_SIZE); > > > > > > } > > > > > > > > public void start() { > > > > > > recorder.setPositionNotificationPeriod(CALLBACK_PERIOD); > > > > > > > recorder.setRecordPositionUpdateListener(newAudioRecord.OnRecordPositionUpdateListener() > { > > > > > > @Override > > > > > > public void onMarkerReached(AudioRecordrecorder) { > > > > > > Log.e(this.getClass().getSimpleName(), "onMarkerReached > > > > > > Called"); > > > > > > } > > > > > > > > @Override > > > > > > public void onPeriodicNotification(AudioRecordrecorder) { > > > > > > Log.e(this.getClass().getSimpleName(), > "onPeriodicNotification > > > > > > Called"); > > > > > > } > > > > > > }); > > > > > > > > recorder.startRecording(); > > > > > > } > > > > > > > > } > --~--~---------~--~----~------------~-------~--~----~ > This message is part of the topic "Using the AudioRecord API" in the > Google Group "Android Developers" > for which you requested email updates. > To stop receiving email updates for this topic, please visit the topic > at http://groups.google.com/group/android-developers/t/2bc6de141f7ffcd1 > -~----------~----~----~----~------~----~------~--~--- > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en