How to determine the time when you finish the offer at registration?

I wrote my own code to record what I say through the microphone. I would like to understand the function that Google uses to stop this recording when there is โ€œsilenceโ€. For example, if I go to Google and click on the microphone symbol, I can say that I plan to search, but what is the function that it uses to understand the moment when I say nothing (the moment of โ€œsilenceโ€)? I was thinking of making a loop in which they record several dB or RMS from several sound frames, and in comparison I can understand if there is "silence". still time is static.

public static void main(String[] args) { final Main REGISTRAZIONE = new Main(); Thread TIME = new Thread(new Runnable() { public void run() { try { Thread.sleep(RECORD_TIME); } catch (InterruptedException ex) { ex.printStackTrace(); } REGISTRAZIONE.finish(); } }); TIME.start(); REGISTRAZIONE.start(); } 
+4
source share
1 answer

Your approach to checking for dB is good. Then you can use another thread to check the silence, and stop the main thread when it finds it. You must use your own implementation of Thread so that it can take TIME as a parameter and stop it when there is silence:

 public class Recorder { static Long RECORD_TIME = 100000L; //or whatever time you use public static void main(String[] args) { final Main REGISTRAZIONE = new Main(); Thread TIME = new Thread(new Runnable() { public void run() { try { Thread.sleep(RECORD_TIME); } catch (InterruptedException ex) { ex.printStackTrace(); } REGISTRAZIONE.finish(); } }); TIME.start(); myThread finisher = new myThread(TIME); finisher.start(); REGISTRAZIONE.start(); } } class myThread extends Thread implements Runnable { private Thread TIME; public myThread(Thread TIME) { this.TIME = TIME; } public void run() { while (!silence()) { // do nothing } TIME.interrupt(); } private boolean silence() { //record and calculate the dB volume and compare to some level return true; } } 
+1
source

Source: https://habr.com/ru/post/1490524/


All Articles