У меня есть java настольное приложение поверх Windows, которое запрашивает доступ к линии микрофона и линии динамика, обычно оно работает правильно, но в конкретном случае оно не получает доступа к микрофону.
Я переместил эту часть кода в отдельное приложение для поиска проблемы.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lineasaudio;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
public class LineasAudio {
static final int INTERNAL_BUFFER_SIZE = 40960;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Creating a File object that represents the disk file.
PrintStream o = null;
try {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
o = new PrintStream(new File("TEST" + dtf.format(now) + ".txt"));
// Assign o to output stream
System.setOut(o);
System.setErr(o);
System.out.println(dtf.format(now));
} catch (FileNotFoundException ex) {
Logger.getLogger(LineasAudio.class.getName()).log(Level.SEVERE, null, ex);
}
// TODO code application logic here
initMicrophoneLine();
System.out.println("");
System.out.println("");
initSpeakerLine();
}
public static void initMicrophoneLine() {
System.out.println("Input Available Mixers:");
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++) {
System.out.print(" " + i + ") " + aInfos[i].getName() + ": " + aInfos[i].getDescription() + "\n");
Mixer mixer = AudioSystem.getMixer(aInfos[i]);
Line.Info[] targetLineInfo = mixer.getTargetLineInfo();
for (Line.Info info : targetLineInfo) {
showLineInfo(info);
}
}
if (aInfos.length == 0) {
System.out.println("WARNING: NO mixers available.");
return;
}
float fFrameRate = 8000.0F;
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, fFrameRate, 16, 1, 2, fFrameRate, false);
Boolean microphone = false;
TargetDataLine target_line = null;
boolean DEBUG = true;
DataLine.Info lineInfo = new DataLine.Info(TargetDataLine.class, format, INTERNAL_BUFFER_SIZE);
if (!AudioSystem.isLineSupported(lineInfo)) {
System.err.println("ERROR: AudioLine not supported by this System.");
}
try {
target_line = (TargetDataLine) AudioSystem.getLine(lineInfo);
if (DEBUG) {
System.out.println("TargetDataLine: " + target_line);
}
target_line.open(format, INTERNAL_BUFFER_SIZE);
microphone = true;
System.out.println("Microphone line found");
} catch (LineUnavailableException e) {
System.err.println("ERROR: LineUnavailableException at AudioSender()");
e.printStackTrace();
} catch (IllegalArgumentException ex) {
System.err.println("ERROR: microphone not found");
ex.printStackTrace();
} finally {
if (!microphone) {
System.err.println("ERROR: microphone not found");
}
}
}
public static void initSpeakerLine() {
System.out.println("Output Available Mixers:");
Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < aInfos.length; i++) {
System.out.print(" " + i + ") " + aInfos[i].getName() + ": " + aInfos[i].getDescription() + "\n");
Mixer mixer = AudioSystem.getMixer(aInfos[i]);
Line.Info[] sourceLineInfo = mixer.getSourceLineInfo();
for (Line.Info info : sourceLineInfo) {
showLineInfo(info);
}
}
if (aInfos.length == 0) {
System.out.println("WARNING: NO mixers available.");
return;
}
float fFrameRate = 8000.0F;
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, fFrameRate, 16, 1, 2, fFrameRate, false);
Boolean speaker = false;
SourceDataLine source_line;
boolean DEBUG = true;
DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, format, INTERNAL_BUFFER_SIZE);
if (!AudioSystem.isLineSupported(lineInfo)) {
System.err.println("ERROR: AudioLine not supported by this System.");
}
try {
source_line = (SourceDataLine) AudioSystem.getLine(lineInfo);
if (DEBUG) {
System.out.println("SourceDataLine: " + source_line);
}
source_line.open(format, INTERNAL_BUFFER_SIZE);
speaker = true;
System.out.println("Speaker line found");
} catch (LineUnavailableException e) {
System.err.println("ERROR: LineUnavailableException at AudioReceiver()");
e.printStackTrace();
} catch (IllegalArgumentException ex) {
System.err.println("ERROR: speaker or headphones not found");
ex.printStackTrace();
} finally {
if (!speaker) {
System.err.println("ERROR: speaker not found");
}
}
}
public static void displayMixerInfo() {
Mixer.Info[] mixersInfo = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixersInfo) {
System.out.println("Mixer: " + mixerInfo.getName());
Mixer mixer = AudioSystem.getMixer(mixerInfo);
Line.Info[] sourceLineInfo = mixer.getSourceLineInfo();
for (Line.Info info : sourceLineInfo) {
showLineInfo(info);
}
Line.Info[] targetLineInfo = mixer.getTargetLineInfo();
for (Line.Info info : targetLineInfo) {
showLineInfo(info);
}
}
}
private static void showLineInfo(final Line.Info lineInfo) {
System.out.println(" " + lineInfo.toString());
if (lineInfo instanceof DataLine.Info) {
DataLine.Info dataLineInfo = (DataLine.Info) lineInfo;
AudioFormat[] formats = dataLineInfo.getFormats();
for (final AudioFormat format : formats) {
System.out.println(" " + format.toString());
}
}
}
}
Получен следующий результат:
2020-01-22_16-37-03
Input Available Mixers:
0) Controlador primario de sonido: Direct Audio Device: DirectSound Playback
1) Teléfono con altavoz con cancelación de eco (Jabra SPEAK 510 USB): Direct Audio Device: DirectSound Playback
2) Digital Output (S/PDIF) (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
3) Altavoces / Auricular (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
4) AMD HDMI Output (AMD High Definition Audio Device): Direct Audio Device: DirectSound Playback
5) Comunicaciones auriculares (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
6) Controlador primario de captura de sonido: Direct Audio Device: DirectSound Capture
interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
7) Teléfono con altavoz con cancel: Direct Audio Device: DirectSound Capture
interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
8) Micrófono (USB Audio Device): Direct Audio Device: DirectSound Capture
interface TargetDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
9) Port Teléfono con altavoz con cancel: Port Mixer
HEADPHONE target port
10) Port Digital Output (S/PDIF) (IDT Hi: Port Mixer
Volumen general target port
11) Port Altavoces / Auricular (IDT High: Port Mixer
SPEAKER target port
12) Port AMD HDMI Output (AMD High Defin: Port Mixer
Volumen general target port
13) Port Comunicaciones auriculares (IDT: Port Mixer
HEADPHONE target port
14) Port Micrófono (USB Audio Device): Port Mixer
Volumen general target port
15) Port Teléfono con altavoz con cancel: Port Mixer
Volumen general target port
TargetDataLine: com.sun.media.sound.DirectAudioDevice$DirectTDL@c34f4d
ERROR: LineUnavailableException at AudioSender()
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at lineasaudio.LineasAudio.initMicrophoneLine(LineasAudio.java:91)
at lineasaudio.LineasAudio.main(LineasAudio.java:53)
ERROR: microphone not found
Output Available Mixers:
0) Controlador primario de sonido: Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
1) Teléfono con altavoz con cancelación de eco (Jabra SPEAK 510 USB): Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
2) Digital Output (S/PDIF) (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
3) Altavoces / Auricular (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
4) AMD HDMI Output (AMD High Definition Audio Device): Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
5) Comunicaciones auriculares (IDT High Definition Audio CODEC): Direct Audio Device: DirectSound Playback
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
6) Controlador primario de captura de sonido: Direct Audio Device: DirectSound Capture
7) Teléfono con altavoz con cancel: Direct Audio Device: DirectSound Capture
8) Micrófono (USB Audio Device): Direct Audio Device: DirectSound Capture
9) Port Teléfono con altavoz con cancel: Port Mixer
10) Port Digital Output (S/PDIF) (IDT Hi: Port Mixer
11) Port Altavoces / Auricular (IDT High: Port Mixer
12) Port AMD HDMI Output (AMD High Defin: Port Mixer
13) Port Comunicaciones auriculares (IDT: Port Mixer
14) Port Micrófono (USB Audio Device): Port Mixer
MICROPHONE source port
15) Port Teléfono con altavoz con cancel: Port Mixer
MICROPHONE source port
SourceDataLine: com.sun.media.sound.DirectAudioDevice$DirectSDL@817b38
Speaker line found
Кроме того, я пробовал с пример приложения oracle , которое, как я выяснил, связано не с указанными параметрами звука, а с тем, что линия отображается как занятая при запросе из системы. Это происходит на настольном компьютере HP с микрофоном Jabra для конференц-связи на Windows, поэтому в принципе я думал, что это будет проблемой с контроллером микрофона, поскольку это микрофон USB, но при тестировании с помощью разъемного микрофона это также происходит.
Мое мнение таково, что это может быть ошибкой аудиодрайверов IDT, но я не могу удалить их, потому что они являются основной системой. Windows прекрасно распознает микрофон, и я также пытался закрыть остальные приложения, которые могли блокировать линию, например, Skype, но проблема сохраняется.
Есть ли способ освободить эту линию или обойти проблема? Заранее спасибо.
ОБНОВЛЕНИЕ:
Выполненные тесты, модифицирующие все возможные параметры для получения аудиолинии, дали тот же результат. Также не получилось попытаться получить линию от микшера напрямую. Каждый раз, когда я получаю доступ к линии, но пытаюсь открыть ее, генерируется исключение, как если бы оно было занято. Я также пытался закрыть линию, прежде чем пытаться открыть ее, чтобы попытаться освободить линию, но я получил тот же результат