How ro record audio?

edited April 2018 in Arduino

Is there a way to record audio output from a sketch? I have code and library to record video that is images, but I am playing back audio and would like to record that as well.

My apologies if this question has already been asked — I have been searching for through the forum, but I could not find a relevant post.

Tagged:

Answers

  • Import the minim library, then use the AudioRecorder object and its save() method:

  • I am trying to use the minim library to record a mp3 that is manipulated with a motion sensor. However, the recordings I am making are coming up empty. Here is my code:

    import processing.serial.*;
    import cc.arduino.*;
    import org.firmata.*;
    import processing.sound.*;
    import ddf.minim.*;
    import ddf.minim.ugens.*;
    
    Arduino ardy;
    
    SoundFile quick;
    int senVal;
    Minim         minim;
    AudioOutput   out;
    AudioRecorder recorder;
    
    void setup() {
      fullScreen(P3D);
      noCursor();
      background(0);
    
      //Getting Arduino Data
      println(Arduino.list());
      ardy = new Arduino(this, "COM3", 57600); 
      ardy.pinMode(0, Arduino.INPUT);
    
      //sound
      quick = new SoundFile(this, "QUICKENING.mp3");
      quick.loop();
    
      //record sound
      minim = new Minim(this);
      out = minim.getLineOut();
      recorder = minim.createRecorder(out, "quickening_live.wav");
    
      frameRate(25);
    }
    
    void draw() {
      //Sensor Data
      senVal = ardy.analogRead(0);
      println(senVal);
      quick.rate(map(senVal, 70, 10, 1, 0.25)); 
    }
    
    void keyReleased(){
      if ( key == 'r' ) {
        if ( recorder.isRecording() ) {
          recorder.endRecord();
        } else {
          recorder.beginRecord();
        }
      }
    
      if ( key == 's' ){
        recorder.save();
        println("Done saving.");
      }
    }
    
  • You should do everything in minim, instead of accessing audio using processing.sound. I will start with these :

    http://code.compartmental.net/minim/audioplayer_method_play.html
    http://code.compartmental.net/minim/minim_method_createrecorder.html

    You can also skip the arduino part. Instead, you can map senVal to the mouse position in the screen to simulate the arduino part:

    quick.rate(map(mouseX, width,0, 1, 0.25));

    Kf

  • Im tryng the same thing without any success.

    this would be the combination of > kfrajer but is coming out empty anyway.``

    `import ddf.minim.*;
    
    import ddf.minim.ugens.*;
    
    Minim         minim;
    AudioOutput   out;
    AudioRecorder recorder;
    AudioPlayer sonido;
    void setup()
    {
      size(512, 200, P3D);
    
      minim = new Minim(this);
    
      out = minim.getLineOut();
      sonido = minim.loadFile("fijo2.wav");
      sonido.loop();
    
      recorder = minim.createRecorder(out, "myrecording.wav");  
      textFont(createFont("Arial", 12));
    }
    
    void draw()
    {
      background(0); 
      stroke(255);
    }
    
    void keyReleased()
    {
      if ( key == 'r' ) 
      {
        if ( recorder.isRecording() ) 
        {
          recorder.endRecord();
        }
        else 
        {
          recorder.beginRecord();
        }
      }
      if ( key == 's' )
      {
        recorder.save();
        println("Done saving.");
      }
    }`
    
This discussion has been closed.