Code: Select all
AudioFormat af = makeAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, af);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Unsupported audio format");
System.out.println(info);
}
Code: Select all
Unsupported audio format interface
TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian
Nachdem ich mir die Oracle-Dokumentation angesehen hatte, habe ich diesen Code ausprobiert:
Code: Select all
if (AudioSystem.isLineSupported(Port.Info.MICROPHONE)) {
Die Audioeingabe funktioniert definitiv mit Audacity und mit dem C-Programm, das ich ersetzen möchte. Das C-Programm verwendet die Leitungseinstellungen, die ich hier angegeben habe.
In Einstellungen/Datenschutz und Sicherheit/Mikrofon ist „Apps Zugriff auf Ihr Mikrofon erlauben“ aktiviert und ich kann Aufzeichnungen von Audacity und meinem C-Programm über das Mikrofon sehen, aber es gibt keinen Verweis auf Java app.
Wenn ich fortfahre und trotzdem versuche, die TargetDataLine zu verwenden, erhalte ich den folgenden Stack-Trace:
Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: No line matching interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian is supported.
at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:423)
at foo.recorder.AudioIn.(AudioIn.java:75)
at foo.recorder.RecorderTab.startRecord(RecorderTab.java:379)
at foo.recorder.RecorderTab$6.buttonPressed(RecorderTab.java:364)
at foo.recorder.NoteClickImage$Listener.onClick(NoteClickImage.java:23)
at foo.recorder.ClickListener.mouseClicked(ClickListener.java:12)
at java.desktop/java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:280)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6624)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398)
at java.desktop/java.awt.Component.processEvent(Component.java:6386)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4584)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Mobile version