Created
September 4, 2013 06:51
-
-
Save h4ck4life/6433506 to your computer and use it in GitHub Desktop.
Android blow detection via microphone. Source: http://stackoverflow.com/a/6186977
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isBlowing() | |
{ | |
boolean recorder=true; | |
int minSize = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); | |
AudioRecord ar = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,minSize); | |
short[] buffer = new short[minSize]; | |
ar.startRecording(); | |
while(recorder) | |
{ | |
ar.read(buffer, 0, minSize); | |
for (short s : buffer) | |
{ | |
if (Math.abs(s) > 27000) //DETECT VOLUME (IF I BLOW IN THE MIC) | |
{ | |
blow_value=Math.abs(s); | |
System.out.println("Blow Value="+blow_value); | |
ar.stop(); | |
recorder=false; | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice code, thx