마이크가 아니라 라인 입력 포트에서 소리를 캡처해야합니다.Java로 라인 입력 포트에서 소리를 녹음하는 방법
마이크에서 녹음을 완료했지만 라인 인 포트 또는 특정 포트에서 사운드를 캡처 할 수 없습니다. 이 문제를 어떻게 해결할 수 있습니까?
마이크가 아니라 라인 입력 포트에서 소리를 캡처해야합니다.Java로 라인 입력 포트에서 소리를 녹음하는 방법
마이크에서 녹음을 완료했지만 라인 인 포트 또는 특정 포트에서 사운드를 캡처 할 수 없습니다. 이 문제를 어떻게 해결할 수 있습니까?
TargetDataLine
클래스를 숙지하십시오. 또한, 자체에서 자바 독 :
대상 데이터 라인
적절한 DataLine.Info 객체 믹서 getLine 메소드를 호출 믹서로부터 얻을 수있다.
특히, Mixer.getTargetLineInfo()
을 검토하고 반환 된 출력을 검사하여 찾고있는 입력 라인 포트와 일치하는 라인을 선택하십시오.
나도이 생각하지만, 실제로이 같은
mixer.getSourceLineInfo()
는 믹서에서보기 ... 정말 혼란 필요가있다!
은 TargetDataLine는 기록 입력 라인,하지만 당신은 믹서 (마이크, LINE_IN, SPDIF,) 즉,이 포트를 볼 필요에서이 라인이 올 수 있습니다 위치를 확인할 수 그래서 당신은
믹서를 호출 할 필요가 .getSourceLineInfo()
이것은 포트만 제공합니다. 예를 들어 LINE_IN 입력의 녹음 볼륨을 제어하는 데 사용할 수 있지만 PORT 객체에서 직접 녹음 할 수는 없습니다.
사용해야합니다. DataLine.Info targetDataLineInfo = new DataLine.Info (TargetDataLine.class, AudioFormat); 당신은 아마 이미했던 것처럼,
Mixer.getLine(audioFormat);
이 당신에게 기록 라인을 줄 것이다 : AudioFormat을가
audioFormat = new AudioFormat(
Encoding.PCM_SIGNED,
sampleRate,
bitRate,
monoOrStereo,
monoOrStereo * 2, //
sampleRate,
false);
같은 일부 사용자 정의 형식이 그런 다음 선호하는 믹서의 라인을 얻을 수있다
...
내가 알 수없는 것은 LINE_IN과 같은 포트를 선택하고 포트 객체가 제어 할 수있는 일치하는 TargetDataLine을 만드는 방법입니다. 나는 거기 작업 예제와
()
누구 ..
이 시도 .. 검색 및 검색했습니다. 그것이 작동한다면 랩톱에서 완전히 테스트 할 수 없으므로 알려주십시오. 그런 다음 자신의 기능을 구성하여 PortMixer
, ActualMixer
및 TargateDataLine
을 지정된 입력 유형 및/또는 원하는 믹서로 가져올 수 있습니다.이 실행
private void testGettingInput() {
//Check this out for interest
//http://www.java-forum.org/spiele-multimedia-programmierung/94699-java-sound-api-zuordnung-port-mixer-input-mixer.html
final String newLine = System.getProperty("line.separator");
final String inputTypeString = "LINE_IN"; // or COMPACT_DISC or MICROPHONE etc ...
final Port.Info myInputType = new Port.Info((Port.class), inputTypeString, true);
final AudioFormat af = new AudioFormat(
Encoding.PCM_SIGNED,
44100.0F,
16,
2,
2 * 2,
44100.0F,
false);
final DataLine.Info targetDataLineInfo = new DataLine.Info(TargetDataLine.class, af);
TargetDataLine targetDataLine;
//Go through the System audio mixers
for (Mixer.Info mixerInfo : AudioSystem.getMixerInfo()) {
try {
Mixer targetMixer = AudioSystem.getMixer(mixerInfo);
targetMixer.open();
//Check if it supports the desired format
if (targetMixer.isLineSupported(targetDataLineInfo)) {
System.out.println(mixerInfo.getName() + " supports recording @" + af);
//now go back and start again trying to match a mixer to a port
//the only way I figured how is by matching name, because
//the port mixer name is the same as the actual mixer with "Port " in front of it
// there MUST be a better way
for (Mixer.Info mifo : AudioSystem.getMixerInfo()) {
String port_string = "Port ";
if ((port_string + mixerInfo.getName()).equals(mifo.getName())) {
System.out.println("Matched Port to Mixer:" + mixerInfo.getName());
Mixer portMixer = AudioSystem.getMixer(mifo);
portMixer.open();
portMixer.isLineSupported((Line.Info) myInputType);
//now check the mixer has the right input type eg LINE_IN
if (portMixer.isLineSupported((Line.Info) myInputType)) {
//OK we have a supported Port Type for the Mixer
//This has all matched (hopefully)
//now just get the record line
//There should be at least 1 line, usually 32 and possible unlimited
// which would be "AudioSystem.Unspecified" if we ask the mixer
//but I haven't checked any of this
targetDataLine = (TargetDataLine) targetMixer.getLine(targetDataLineInfo);
System.out.println("Got TargetDataLine from :" + targetMixer.getMixerInfo().getName());
return;
}
}
}
System.out.println(newLine);
}
targetMixer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
import javax.sound.sampled.*;
/**
*
* @author d07114915
*
* Class to get a mixer with a specified recordable audio format from a specified port
* For instance get a 44.1kHz 16bit record line for a "line in" input
*/
public class MixerMatcher {
private static final String THE_INPUT_TYPE_I_WANT = "MICROPHONE";
private static final String THE_NAME_OF_THE_MIXER_I_WANT_TO_GET_THE_INPUT_FROM = "Realtek HD Audio Input";
private static final AudioFormat af = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
44100.0F,
16,
2,
2 * 2,
44100.0F,
false);
private static final DataLine.Info targetDataLineInfo = new DataLine.Info(TargetDataLine.class, af);
private static final Port.Info myInputType = new Port.Info((Port.class), THE_INPUT_TYPE_I_WANT, true);
private static TargetDataLine targetDataLine = null;
public static void main(String[] args) {
Mixer portMixer = null;
Mixer targetMixer = null;
try {
for (Mixer.Info mi : AudioSystem.getMixerInfo()) {
// System.out.println("-" +mi.getName() + "-");
if (mi.getName().equals(THE_NAME_OF_THE_MIXER_I_WANT_TO_GET_THE_INPUT_FROM)) {
System.out.println("Trying to get portMixer for :" + mi.getName());
portMixer = getPortMixerInfoFor(mi);
if (portMixer != null) {
System.out.println(portMixer.getMixerInfo().toString());
targetMixer = AudioSystem.getMixer(mi);
break;
}
}
}
if (targetMixer != null) {
targetMixer.open();
targetDataLine = (TargetDataLine) targetMixer.getLine(targetDataLineInfo);
System.out.println("Got TargetDataLine from :" + targetMixer.getMixerInfo().getName());
portMixer.open();
Port port = (Port) portMixer.getLine(myInputType);
port.open();
Control[] controls = port.getControls();
System.out.println((controls.length > 0 ? "Controls for the "+ THE_INPUT_TYPE_I_WANT + " port:" : "The port has no controls."));
for (Control c : controls) {
System.out.println(c.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
//return the portMixer that corresponds to TargetMixer
private static Mixer getPortMixerInfoFor(Mixer.Info mixerInfo) {
//Check this out for interest
//http://www.java-forum.org/spiele-multimedia-programmierung/94699-java-sound-api-zuordnung-port-mixer-input-mixer.html
try {
// get the requested mixer
Mixer targetMixer = AudioSystem.getMixer(mixerInfo);
targetMixer.open();
//Check if it supports the desired format
if (targetMixer.isLineSupported(targetDataLineInfo)) {
System.out.println(mixerInfo.getName() + " supports recording @ " + af);
//now go back and start again trying to match a mixer to a port
//the only way I figured how is by matching name, because
//the port mixer name is the same as the actual mixer with "Port " in front of it
// there MUST be a better way
for (Mixer.Info portMixerInfo : AudioSystem.getMixerInfo()) {
String port_string = "Port ";
if ((port_string + mixerInfo.getName()).equals(portMixerInfo.getName())) {
System.out.println("Matched Port to Mixer:" + mixerInfo.getName());
Mixer portMixer = AudioSystem.getMixer(portMixerInfo);
portMixer.open();
//now check the mixer has the right input type eg LINE_IN
boolean lineTypeSupported = portMixer.isLineSupported((Line.Info) myInputType);
System.out.println(portMixerInfo.getName() +" does " + (lineTypeSupported? "" : "NOT") + " support " + myInputType.getName());
if (lineTypeSupported) {
portMixer.close();
targetMixer.close();
return portMixer;
}
portMixer.close();
}
}
}
targetMixer.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
내가 얻을 : (주 8이 :
Trying to get portMixer for :Realtek HD Audio Input
Realtek HD Audio Input supports recording @ PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
Matched Port to Mixer:Realtek HD Audio Input
Port Realtek HD Audio Input does support MICROPHONE
Port Realtek HD Audio Input, version 5.10
Got TargetDataLine from :Realtek HD Audio Input
Controls for the MICROPHONE port:
Mic Volume Control containing Select, Microphone Boost, Volume, and Balance Controls.
믹서 입력 유형 환경 설정 변경 "USB 사운드 장치"와 ""LINE_IN "각각 나는 다음과 같은 결과를 얻으 흰색 단어 "장치"후 믹서 이름에 공백이 있지만,이 웹 페이지에 표시되지 않습니다!)
Trying to get portMixer for :USB Sound Device
Trying to get portMixer for :USB Sound Device
USB Sound Device supports recording @ PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
Matched Port to Mixer:USB Sound Device
Port USB Sound Device does support LINE_IN
Port USB Sound Device , version 0.16
Got TargetDataLine from :USB Sound Device
Controls for the LINE_IN port:
Line Control containing Select, Mute, Volume, and Balance Controls.
USB 사운드 카드에 입력 포트와 출력 포트가 표시되어 그 중 하나가 LINE_IN을 지원하지 않습니다. 이는 출력이므로 "스테레오 믹스"또는 기타 출력 유형을 녹음 할 수 있습니다.
희망이 작품과 누군가 .... 도움이되는 자바 문서는 상당히 막연하다 ... 리눅스에서 LINE_IN과 같은 포트 이름을 인식하지 못 하겠지만, 더 많은 정보
의 믹서 이름 등 ... 마이크는 "캡처"라고 내 리눅스에 ...확인 jsresources.org FAQ 하위 문자열을 필요로 같은 OS 포트는 아마도 몇 가지 다른 일이며,
오류 개선 등 알려주세요.
d07114915
어떤 플랫폼을 사용하십니까? Java 사운드는 OS와 OS가 약간 다릅니다. – joev