Question #138406

The following pseudo-code represents the algorithm of the pitch changing detector of the Voice Interaction technique shown in the lecture video.

Answer the correct combination of code fragments to fill in the blanks.

Expert's answer

AudioDispatcher dispatcher;

dispatcher= AudioDispatcher.fromDefaultMicrophone(1024, 0);

dispatcher.addAudioProcessor(new AudioProcessor() {

 float threshold = -70;

//dB @Override

public boolean process(AudioEvent audioEvent) {

 float[] buffer = audioEvent.getFloatBuffer();

double level = soundPressureLevel(buffer);

if(level > threshold){

System.out.println("Sound detected.");

} return true;

}

@Override

 public void processingFinished() {}

/**

* Returns the dBSPL for a buffer.

*/

private double soundPressureLevel(final float[] buffer) {

double power = 0.0D; for (float element : buffer) {

 power += element * element; }

double value = Math.pow(power, 0.5)/ buffer.length;
 return 20.0 * Math.log10(value); 
  } 
});
LATEST TUTORIALS
APPROVED BY CLIENTS