0

How can i write a java program that starts recording sound when the sound captured by the microphone is enough loud, and stops when the sound is not loud.

In other words, there is no time limit for recording - when the wave ends ,the program stops recording

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Redan Hassoun
  • 106
  • 2
  • 9

1 Answers1

0

Whilst I'm not overly familiar with the Java Sound API, a quick google search of Java Sound API provides a lot of information and code snippets.

You could use something like this

In order to start or stop the recording based on volume level, you could call the getLevel() method on the DataLine Object as a condition prior to line.Start() and line.stop() methods to check current volume from your mic.

i.e.

if(line.getLevel() < 0.3){
     line.stop(); 

description of getLevel() method from javadocs Obtains the current volume level for the line. This level is a measure of the signal's current amplitude,The range is from 0.0 (silence) to 1.0 (maximum possible amplitude for the sound waveform). The units measure linear amplitude, not decibels.

BenRowley
  • 24
  • 7
  • *"In order to start or stop the recording based on volume level, you could call the getLevel() method on the DataLine Object"* That wouldn't do any good. It is the 'volume level' that the line is set at and does not change (unless the end user or an app. changes it). To get the level of the actual sound it is necessary to perform an RMS or dB calculation on the data. – Andrew Thompson May 02 '16 at 03:06