Android Audio Analysis in Real-time

荒凉一梦 提交于 2019-12-20 09:38:58

问题


I have searched for this online, but am still a bit confused (as I'm sure others will be if they think of something like this). I'd like to preface by saying that this is not for homework and/or profit.

I wanted to create an app that could listen to your microwave as you prepare popcorn. It would work by sounding an alarm when there's a certain time interval between pops (say 5-6 seconds). Again, this is simply a project to keep me occupied - not for a class.

Either way, I'm having trouble trying to figure out how to analyze the audio intake in real-time. That is, I need a way to log the time when a "pop" occurs. So that you guys don't think I didn't do any research into the matter, I've checked out this SO question and have extensively searched the AudioRecord function list.

I'm thinking that I will probably have to do something with one of the versions of read() and then compare the recorded audio every 2 seconds or so to the recorded audio of a "pop" (i.e. if 70% or more of the byte[] audioData array is the same as that of a popping sound, then log the time). Can anyone with Android audio input experience let me know if I'm at least on the right track? This is not a question of me wanting you to code anything for me, but a question as to whether I'm on the correct track, and, if not, which direction I should head instead.


回答1:


Check out this code (ignore the playback part): Playing back sound coming from microphone in real-time

Basically the idea is that you will have to take the value of each 16-bit sample (which corresponds to the value of the wave at that time). Using the sampling rate, you can calculate the time between peaks in volume. I think that might accomplish what you want.




回答2:


I think I have an easier way.

You could use the MediaRecorder 's getMaxAmplitude method.

Anytime your recorder detects a big jump in amplitude, you have detected a corn pop!




回答3:


this may be a bit overkill, but there is a framework from MIT media labs called funf: http://code.google.com/p/funf-open-sensing-framework/
They already created classes for audio input and some analysis (FFT and the like), also saving to files or uploading is implemented as far as I've seen, and they handle most of the sensors available on the phone. You can also get inspired from the code they wrote, which I think is pretty good.




回答4:


We've published an open source Android spectrum analyzer on Github here which computes FFT on an audio from the microphone and displays a 2D spectrogram.

You can see a video of it in action at https://youtu.be/yU05fsgOYO4

Critical code for reading the mic & computing the audio spectra is found at v2.x / ... sciShowcase / Viewmodels / AudioAnalyzer



来源:https://stackoverflow.com/questions/7404828/android-audio-analysis-in-real-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!