注意:我不想“读取音频文件foo.bar并播放它”。
我想以编程方式在飞行中生成音频文件并播放它们。
Java有没有内置的库来实现这一点,或者这是否属于系统依赖库?
谢谢!
发布于 2010-01-14 20:49:39
This Sun forum post有一些用于生成正弦音调的有趣代码。此外,鉴于WAV文件格式不是非常复杂,您可以创建一个表示所需波形的表,然后将其写入文件。有几个例子,例如a raw audio converter和how to write a wav file。
发布于 2014-12-25 20:05:40
最简单的方法是使用java内置的MIDI库:
int channel = 0; // 0 is a piano, 9 is percussion, other channels are for other instruments
int volume = 80; // between 0 et 127
int duration = 200; // in milliseconds
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
MidiChannel[] channels = synth.getChannels();
// --------------------------------------
// Play a few notes.
// The two arguments to the noteOn() method are:
// "MIDI note number" (pitch of the note),
// and "velocity" (i.e., volume, or intensity).
// Each of these arguments is between 0 and 127.
channels[channel].noteOn( 60, volume ); // C note
Thread.sleep( duration );
channels[channel].noteOff( 60 );
channels[channel].noteOn( 62, volume ); // D note
Thread.sleep( duration );
channels[channel].noteOff( 62 );
channels[channel].noteOn( 64, volume ); // E note
Thread.sleep( duration );
channels[channel].noteOff( 64 );
Thread.sleep( 500 );
// --------------------------------------
// Play a C major chord.
channels[channel].noteOn( 60, volume ); // C
channels[channel].noteOn( 64, volume ); // E
channels[channel].noteOn( 67, volume ); // G
Thread.sleep( 3000 );
channels[channel].allNotesOff();
Thread.sleep( 500 );
synth.close();
}
catch (Exception e) {
e.printStackTrace();
}
发布于 2010-01-14 20:46:20
你看过JSyn吗?我不认为Java Core库可以做您想要的事情。
https://stackoverflow.com/questions/2064066
复制相似问题