Processing 处理中的最小值-从麦克风录制,但无法关闭并进行新录制

Processing 处理中的最小值-从麦克风录制,但无法关闭并进行新录制,processing,audio-recording,minim,Processing,Audio Recording,Minim,使用processing.org(在Win8上)中的示例文件,我得到了“从麦克风录制”并播放()声音正常。我只需要一次记录10到30秒。但是现在找不到任何方法来关闭现有的录音并录制新的。 我已经试过各种方法了。我希望能够按另一个键,再次按“r”,再录制几秒钟,就像语言词汇练习之类。 我使用的是来自隔间.net/minim的minim示例代码。官方文档只列出了beginRecord/endRecord,但没有关闭现有记录并开始另一个记录的方法。没有诸如recorder.close()或.reset

使用processing.org(在Win8上)中的示例文件,我得到了“从麦克风录制”并播放()声音正常。我只需要一次记录10到30秒。但是现在找不到任何方法来关闭现有的录音并录制新的。
我已经试过各种方法了。我希望能够按另一个键,再次按“r”,再录制几秒钟,就像语言词汇练习之类。
我使用的是来自隔间.net/minim的minim示例代码。官方文档只列出了beginRecord/endRecord,但没有关闭现有记录并开始另一个记录的方法。没有诸如recorder.close()或.reset/restart等内容

导入ddf.minim.*;
进口ddf.minim.ugens.*;
极小极小;
//记录
音频输入;
录音机;
布尔记录;
//用于播放
音频输出;
文件播放器;
无效设置()
{大小(512,200,P3D);
最小值=新的最小值(本);
in=最小getLineIn(最小立体声,2048);
//创建录音机
记录器=最小创建记录器(在“myrecording.wav”中);
//获得输出
out=最小getLineOut(最小立体声);
textFont(createFont(“Arial”,24));
}
作废提款()
{背景(255240128);
中风(32);
if(recorder.isRecording())
{text(“现在录制,按r键停止录制。”,5,15);}
否则,如果(!已记录)
{text(“按R键开始录制。”,5,15);}
其他的
{text(“按S键将录音保存到磁盘并在草图中播放。”,5,15);}
} 
//末端牵引
void keyReleased()
{
如果(!recorded&&key=='r')
{//表示要开始或停止捕获音频数据,
if(recorder.isRecording())
{recorder.endRecord();
已记录=真;}
其他的
{recorder.beginRecord();}
}
如果(记录的和键=='s')
{//现在将其写入文件
//在缓冲记录的情况下,如果缓冲区较大,将冻结草图一段时间
//在流式录制的情况下,不会冻结所有正在进行的操作
//所要做的就是关闭文件。
//save返回AudioRecordingStream中录制的音频,
//然后我们可以用文件播放器播放
如果(玩家!=null)
{球员.解锁(出局);
player.close();}
player=新文件播放器(recorder.save());
玩家。补丁(退出);
player.play();
}
//我的补充-这再次适用于游戏
如果(记录的和键='p')
{player.rewind();
player.play();
}
我试图关闭minim并重新启动它,但它抱怨“没有使用局部变量xxx”,比如:不工作

if(键=='x')
{minim.stop();
最小值=新的最小值(本);
音频输入;
录音机;
音频输出;
FilePlayer;}

只需重新初始化记录器即可:

recorder = minim.createRecorder(in, "myrecording.wav");
我建议使用时间戳或文件计数器,这样您就不会覆盖以前的录音

这里有一个非常简单的示例(也出现在示例>贡献库>最小值>基础>RecordAudioInput中):

此外,如果您希望使用“保存”对话框而不是为.wav文件生成唯一的名称,则可能需要签出。

请发布一个小示例程序,演示该问题,我们可以复制并粘贴该程序以自行运行。
/**
  * 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 - "+new java.util.Date()+".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 = minim.createRecorder(in, "myrecording - "+new java.util.Date()+".wav");
      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.");
  }
}