2014-01-17 4 views
4

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(); 
} 
} 
+1

나는 혼란 스럽다. "내 마이크에서 오는 것처럼"어떻게 의미합니까? –

답변

1

가상 오디오 케이블과 같은 프로그램을 설치하고 음악 플레이어에서 재생 사운드를 가상 입력으로 리디렉션 할 수 있습니다. 프로그램에서 가상 입력 소스를 청취하고 테스트를 위해 일반 헤드폰이나 스피커 수신 신호로 리다이렉트하거나 파일에 저장할 수 있습니다.

+0

예, 그렇습니다. VoiceMeeter를 설치해야했습니다. 그것은 당신이 언급 한 Virtual Audio Cable과 같은 사람으로부터 온 것입니다. 위의 질문을 최종 해결책으로 편집하겠습니다. 라인 정보를 얻는 방법에 만족하지 않습니다. 모든 믹서를 반복하는 대신 믹서가 어떻게 호출되는지 알고 있다면 다른 방법이 있습니까? –

관련 문제