gpt4 book ai didi

audio - 如何在麦克风中播放声音?

转载 作者:行者123 更新时间:2023-12-03 02:30:45 26 4
gpt4 key购买 nike

我想用处理语言制作一个音板来播放声音,以便计算机处理声音,就好像它们是我的麦克风输入的声音一样。这是我做音板的唯一问题。如何使声音像麦克风录制的声音一样播放?

我已经花了一个小时的时间搜索并尝试获得帮助,但是却没有任何工作可做。

最佳答案

Minim provides the class AudioInput for monitoring the user’s current record source (this is often set in the sound card control panel), such as the microphone or the line-in





http://code.compartmental.net/tools/minim/quickstart/

编辑:

你见过这个吗?
import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;

// for recording
AudioInput in;
AudioRecorder recorder;

// for playing back
AudioOutput out;
FilePlayer player;

void setup()
{
size(512, 200, P3D);

minim = new Minim(this);

// get a stereo line-in: sample buffer length of 2048
// default sample rate is 44100, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 2048);

// create an AudioRecorder that will record from in to the filename specified.
// the file will be located in the sketch's main folder.
recorder = minim.createRecorder(in, "myrecording.wav");

// get an output we can playback the recording on
out = minim.getLineOut( Minim.STEREO );

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.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);
}

if ( recorder.isRecording() )
{
text("Now 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 callstartRecording() and stopRecording() 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 to the end of the file.
if ( recorder.isRecording() )
{
recorder.endRecord();
}
else
{
recorder.beginRecord();
}
}
if ( key == 's' )
{
// we've filled the file out buffer,
// now write it to a file of the type we specified in setup
// in the case of buffered recording,
// this will appear to freeze the sketch for sometime, if the buffer is large
// 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.
// save returns the recorded audio in an AudioRecordingStream,
// which we can then play with a FilePlayer
if ( player != null )
{
player.unpatch( out );
player.close();
}
player = new FilePlayer( recorder.save() );
player.patch( out );
player.play();
}
}

从这里:

http://code.compartmental.net/minim/audiorecorder_class_audiorecorder.html

关于audio - 如何在麦克风中播放声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com