1

I'm trying to trigger an event based on audio input but I have no idea how to go about this. Searching online, I have found numerous tutorials on how to record audio to a file, but nothing on how to analyze microphone input.

If I could figure out how to say, animate the UI based off of volume, like the bar that goes up and down during a voice search, I could hopefully figure out the rest. I'm not looking to do anything complicated like voice recognition, I'm just using it to detect when a signal is received through the 3.5mm microphone from another device.

At this point, I'm not even sure what I should be searching for.

Thanks for any help.

Matt
  • 2,650
  • 4
  • 36
  • 46

2 Answers2

2

From a theoretical perspective, what you'll what to learn about are called "fourier transforms". However, I recommend for an immediately applicable practical application you check out this .

I hope this helps,

-Brian J. Stinar-

Community
  • 1
  • 1
Brian Stinar
  • 1,080
  • 1
  • 14
  • 32
  • That should help allot! My application would be similar to his in that it would be listening to and timing pulses, but I shouldn't have the volume problem. Is there a way to "record" without saving to a file? I just want my app to listen to the audio, I never need to save or replay it. Will it work if I don't set the output file? – Matt Apr 21 '11 at 00:27
  • Hello, I'm not totally certain, but it looks like getMaxAmplitude() "Returns the maximum absolute amplitude that was sampled since the last call to this" so, it looks like you could just have a sampling interval along which you call this, and it will give you the maximum amplitude along that sampling period. I think. Try the example they provided in the below link, just don't call the recorder.setOutputFile(), and see what happens. Since I don't actually have an android, or an emulation platform I can't try it easily... http://developer.android.com/reference/android/media/MediaRecorder.html – Brian Stinar Apr 21 '11 at 16:00
  • If it does require a file, try searching for temporary files. I bet android provides a temp file API. If they don't, you can always throw away your file at the end if you NEED to call setOutputFile(). Good luck! – Brian Stinar Apr 21 '11 at 16:06
  • OK, there is a system for creating temporary files, but this app will be listening for a long time perhaps hours on end. How do I make sure the file size doesn't get out of hand while it is recording? – Matt Apr 21 '11 at 19:28
  • I'm going to go ahead and select this as my answer as it sort of works. The problem is I need to sample at a maximum of 5ms intervals and if I try and call getMaxAmplitude() more than once every 200ms, I'm getting it flickering between the input and 0... Looks like I'm going to have to look at the bytes coming in through AudioReader instead of using MediaRecorder. – Matt Apr 22 '11 at 00:02
  • Yeah, the sampling interval makes sense with flicker and noise. If you go the getMaxAmplitude() route, you can always throw away your temp files with some frequency as well. If you analyze the byte stream, that will be less wasteful but you won't have the nice abstractions MediaRecorder provides. If you're just looking for intensity across all frequencies, your analysis shouldn't be too difficult at all (I imagine it's just reading a single value in the stream.) If you want to split out frequencies that's where the Fourier analysis would come in. Do you have a link to the specs for the stream? – Brian Stinar Apr 22 '11 at 16:04
0

Is it possible to build an application that analyzes my own voice during a call and displays the amplitude in real time either in the foreground or captures it in the background. Or if my voice goes over a certain amplitude it triggers a local notification (during a call).

Craig
  • 19
  • 2