我正在尝试创建一段很长的音频,它是录制的音频剪辑的集合,这些剪辑及时合并成一个大的声音拼贴画。我正在使用 Minim 声音库,但目前我很难让它工作。这与我的编程技能相当基本相同,但我认为这将是一项非常容易的任务!我 :ant 它的工作方式与 Minim 示例文件夹中的“RecordAndPlayback”完全相同,但要让点击触发的事件自动完成。
这是我到目前为止的代码:
import ddf.minim.*;
Minim minim;
AudioInput in;
AudioRecorder recorder;
AudioPlayer player;
Timer timer;
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if 5,000 ms have passed.
// The work of the timer is farmed out to this method.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}
void setup()
{
size(512, 200, P3D);
textMode(SCREEN);
minim = new Minim(this);
timer = new Timer(5000);
timer.start();
in = minim.getLineIn(Minim.STEREO, 2048);
recorder = minim.createRecorder(in, "myrecording.wav", true);
textFont(createFont("Arial", 12));
}
void draw()
{
background(0);
player = minim.loadFile("myrecording.wav");
player.play();
player.loop();
//GUI
stroke(255);
for(int i = 0; i < in.left.size()-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);
}
//-- end of GUI
//recorder switching
if (timer.isFinished())
{
text("not..", 5, 15);
if(recorder.isRecording() == true){
recorder.endRecord();
recorder.save();
timer.start();
}
}else
{
text("recording...", 5, 15);
recorder.beginRecord();
println(recorder.isRecording());
}
///--- end recorder switching
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
if ( player != null )
{
player.close();
}
minim.stop();
super.stop();
}
请任何帮助都会受到欢迎,因为这让我发疯!
谢谢
丹尼尔