Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Detect silence while recording audio.

$
0
0
Hi,

Here's what I ended up writing.

  1. import ddf.minim.*;
    import ddf.minim.analysis.*;

    Minim minim;
    AudioInput audioIn;
    AudioRecorder recorder;
    BeatDetect beat;

    int savedTime;
    int silenceTime = 5000;
     
    void setup()
    {
      size(512, 200);
      background(0); 

      int bufferSize = 4096;
      float sampleRate = 44100;

      minim = new Minim(this);
      audioIn = minim.getLineIn(Minim.STEREO, bufferSize, sampleRate);
      recorder = minim.createRecorder(audioIn, "myrecording.wav", true);
     
      beat = new BeatDetect(bufferSize, sampleRate);
      beat.setSensitivity(200); //in milliseconds
      beat.detectMode(BeatDetect.SOUND_ENERGY);
    }
     
    void draw()
    {
      beat.detect(audioIn.mix);
     
      if (beat.isOnset()){
          println( "Beat detected..." );
          if ( recorder.isRecording() == false ){
            recorder.beginRecord();
            println( "Recording started" );
          }
          savedTime = millis(); //reset counter to now
      }
      else {
       
          int passedTime = millis() - savedTime;
          println( passedTime );

           if (passedTime > silenceTime) {
              println( "5 seconds have passed" );
              savedTime = millis(); // Save the current time to restart the timer!
              recorder.endRecord();
              println( "Stop recording" );
              recorder.save();
              println("Done saving");
              exit();
           }
        }
    }


Viewing all articles
Browse latest Browse all 1768

Trending Articles