# How to record many Audio Recorder?

**URL:** <https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244>\
**Category:** Libraries\
**Created:** [October 8, 2018, 9:34am UTC](https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244 "2018-10-08T09:34:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocolembo](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cocolembo](https://discourse.processing.org/u/cocolembo)\
**Post date:** [October 8, 2018, 9:34am UTC](https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244/1 "2018-10-08T09:34:40Z")

</div>

Hi,

I’m a beginner in Processing, here is a code to record an audio from micro input. (from minim library)

The sketch allow to record an audio but just only one recording.

I would like to record a new recording at each time we press to the r key.

Is someone can help me please ?

Thank’s in advance

```auto
/**
  * This sketch demonstrates how to an <code>AudioRecorder</code> to record audio to disk. 
  * To use this sketch you need to have something plugged into the line-in on your computer, 
  * or else be working on a laptop with an active built-in microphone. 
  * <p>
  * Press 'r' to toggle recording on and off and the press 's' to save to disk. 
  * The recorded file will be placed in the sketch folder of the sketch.
  * <p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;

Minim minim;
AudioInput in;
AudioRecorder recorder;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);

  in = minim.getLineIn();
  // create a recorder that will record from the input to the filename specified
  // the file will be located in the sketch's root folder.
  recorder = minim.createRecorder(in, "myrecording.wav");
  
  textFont(createFont("Arial", 12));
}

void draw()
{
  background(0); 
  stroke(255);
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  for(int i = 0; i < in.bufferSize() - 1; i++)
  {
    line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
    line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
  }
  
  if ( recorder.isRecording() )
  {
    text("Currently recording...", 5, 15);
  }
  else
  {
    text("Not recording.", 5, 15);
  }
}

void keyReleased()
{
  if ( key == 'r' ) 
  {
    // to indicate that you want to start or stop capturing audio data, you must call
    // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
    // as many times as you like, the audio data will be appended to the end of the buffer 
    // (in the case of buffered recording) or to the end of the file (in the case of streamed recording). 
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( key == 's' )
  {
    // we've filled the file out buffer, 
    // now write it to the file we specified in createRecorder
    // in the case of buffered recording, if the buffer is large, 
    // this will appear to freeze the sketch for sometime
    // in the case of streamed recording, 
    // it will not freeze as the data is already in the file and all that is being done
    // is closing the file.
    // the method returns the recorded audio as an AudioRecording, 
    // see the example AudioRecorder >> RecordAndPlayback for more about that
    recorder.save();
    println("Done saving.");
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 8, 2018, 9:51am UTC](https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244/2 "2018-10-08T09:51:33Z")

</div>

it looks like [here](https://stackoverflow.com/questions/44431335/minim-in-processing-record-from-mic-but-cannot-close-and-make-new-recording) is a good answer

---

<div class="post-metadata">

**Author:** ![cocolembo](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cocolembo](https://discourse.processing.org/u/cocolembo)\
**Post date:** [October 8, 2018, 10:20am UTC](https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244/3 "2018-10-08T10:20:30Z")

</div>

Thank’s for the reply, it helps but the first time we record, the first recording doesn’t work

---

<div class="post-metadata">

**Author:** ![zqviel](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zqviel](https://discourse.processing.org/u/zqviel)\
**Post date:** [June 26, 2022, 9:52pm UTC](https://discourse.processing.org/t/how-to-record-many-audio-recorder/4244/4 "2022-06-26T21:52:53Z")

</div>

it didn’t work in my case. when i started to record the program crashes and prints this error in the console: ==== JavaSound Minim Error ====  
==== Error obtaining new output stream: E:\Users\ezequ\OneDrive\Escritorio\facu\MULTIMEDIA\informatica aplicada I\minim\minim\examples\Basics\RecordAudioOutput\myrecording - Sun Jun 26 18:49:52 ART 2022.wav (El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos)

java.lang.NullPointerException: Cannot invoke “org.tritonus.share.sampled.file.AudioOutputStream.write(byte, int, int)” because “this.aos” is null  
at ddf.minim.javasound.JSStreamingSampleRecorder.samples(JSStreamingSampleRecorder.java:177)  
at ddf.minim.SignalSplitter.samples(SignalSplitter.java:112)  
at ddf.minim.javasound.JSAudioOutput.run(JSAudioOutput.java:84)  
NullPointerException  
Could not run the sketch (Target VM failed to initialize).  
For more information, read Help ? Troubleshooting.
