当前位置: 技术问答>java相关
请教一个sound有关的问题?
来源: 互联网 发布时间:2015-03-17
本文导语: 在java中怎样控制扬声器发声! 如有源码将不胜感激! | import java.awt.*; import javax.sound.midi.*; public class Beeper { public void beep(int notePitch,int duration) { ...
在java中怎样控制扬声器发声!
如有源码将不胜感激!
如有源码将不胜感激!
|
import java.awt.*;
import javax.sound.midi.*;
public class Beeper {
public void beep(int notePitch,int duration) {
beep(notePitch,duration,100,100,0);
}
public static void beep(int notePitch,long duration,int velocity,int numInstr,int numChannel) {
Synthesizer mySynthesizer=null;
try {
mySynthesizer = MidiSystem.getSynthesizer();
if ( mySynthesizer == null) {
System.out.println("getSynthesizer() failed!");
return;
}
mySynthesizer.open();
}catch (Exception ex) {
ex.printStackTrace();
return;
}
Instrument[] instruments=mySynthesizer.getAvailableInstruments();
if(numInstr
import javax.sound.midi.*;
public class Beeper {
public void beep(int notePitch,int duration) {
beep(notePitch,duration,100,100,0);
}
public static void beep(int notePitch,long duration,int velocity,int numInstr,int numChannel) {
Synthesizer mySynthesizer=null;
try {
mySynthesizer = MidiSystem.getSynthesizer();
if ( mySynthesizer == null) {
System.out.println("getSynthesizer() failed!");
return;
}
mySynthesizer.open();
}catch (Exception ex) {
ex.printStackTrace();
return;
}
Instrument[] instruments=mySynthesizer.getAvailableInstruments();
if(numInstr