wav 파일을 읽고 마이크에서 출력되는 것처럼 출력을 보내는 작은 프로그램을 작성하려고합니다. 불행히도 사운드 API에 대한 많은 경험이 없습니다.마이크 입력을 시뮬레이트합니다.
배경 : 기본적으로 실현하려는 것은 음성 채팅 중에 (즉, Teamspeak, Ventrilo) 소리를내는 프로그램입니다. 이제는 녹음 장치를 "들으십시오"로 전환하고 사운드를 재생 한 다음 마이크로 다시 전환해야합니다. 프로그램은 마이크에서 입력을 시뮬레이트해야합니다.
지금까지 나는 사운드를 재생하는 것 이상을 얻을 수 없었습니다. 나는 단지 다른 소스 라인이 필요하다고 생각하니?
public class Player {
private final int BUFFER_SIZE = 128000;
private AudioInputStream audioStream;
private AudioFormat audioFormat;
private SourceDataLine sourceLine;
public void playSound(File soundFile) {
try {
audioStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
audioFormat = audioStream.getFormat();
DataLine.Info infoIn = new DataLine.Info(SourceDataLine.class,
audioFormat);
try {
sourceLine = (SourceDataLine) AudioSystem.getLine(infoIn);
sourceLine.open(audioFormat);
} catch (LineUnavailableException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
sourceLine.start();
int nBytesRead = 0;
byte[] abData = new byte[BUFFER_SIZE];
while (nBytesRead != -1) {
try {
nBytesRead = audioStream.read(abData, 0, abData.length);
} catch (IOException e) {
e.printStackTrace();
}
if (nBytesRead >= 0) {
@SuppressWarnings("unused")
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
}
}
sourceLine.drain();
sourceLine.close();
}
}
솔루션 : 설치 VB 오디오 케이블 (http://vb-audio.pagesperso-orange.fr/Cable/). 기부 도구입니다. VB-Output 표준 기록 장치를 만드십시오. 마이크 속성에서 VB 입력을 재생으로 선택하십시오.
public class Player {
private final int BUFFER_SIZE = 128000;
private AudioInputStream audioStream;
private AudioFormat audioFormat;
private SourceDataLine sourceLine;
public void playSound(File soundFile) {
try {
audioStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
audioFormat = audioStream.getFormat();
DataLine.Info infoIn = new DataLine.Info(SourceDataLine.class,
audioFormat);
try {
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
Mixer mixer = null;
for (int i = 0; i < mixerInfos.length; i++) {
System.out.println(mixerInfos[i].getName());
if (mixerInfos[i].getName().equals(
"CABLE Input (VB-Audio Virtual Cable)")) {
mixer = AudioSystem.getMixer(mixerInfos[i]);
break;
}
}
sourceLine = (SourceDataLine) mixer.getLine(infoIn);
sourceLine.open(audioFormat);
} catch (LineUnavailableException e) {
e.printStackTrace();
System.exit(1);
}
sourceLine.start();
int nBytesRead = 0;
byte[] abData = new byte[BUFFER_SIZE];
while (nBytesRead != -1) {
try {
nBytesRead = audioStream.read(abData, 0, abData.length);
} catch (IOException e) {
e.printStackTrace();
}
if (nBytesRead >= 0) {
@SuppressWarnings("unused")
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
}
}
sourceLine.drain();
sourceLine.close();
}
}
나는 혼란 스럽다. "내 마이크에서 오는 것처럼"어떻게 의미합니까? –