[英]Play wav file on Raspberry using Java
How can I reproduce a.wav file using Java on Raspberry (OS: Raspbian)?如何在 Raspberry(操作系统:Raspbian)上使用 Java 重现 a.wav 文件? I tried this and it worked, but not anymore: now the program crashes when it tries to play the file (and I don't know why):
我尝试了这个并且它有效,但不再有效:现在程序在尝试播放文件时崩溃(我不知道为什么):
try{
File adv = new File(pathRasp+"Suoni/avviso20.wav");
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(adv));
clip.start();
}catch(IOException | LineUnavailableException | UnsupportedAudioFileException ex){
System.out.println("ERROR" + ex);
}
Anyone know any other ways to reproduce.wav files?任何人都知道任何其他方法来重现.wav 文件?
I found this blog post which may or may not help:我发现这篇博文可能有帮助,也可能没有帮助:
https://nealvs.wordpress.com/2017/08/11/java-sound-on-a-raspberry-pi-with-openjdk/ https://nealvs.wordpress.com/2017/08/11/java-sound-on-a-raspberry-pi-with-openjdk/
I was pretty bummed when my sound stopped playing on my Raspberry Pi when I switched to OpenJDK 8 after originally using Oracle JDK 8.
当我在最初使用 Oracle JDK 8 后切换到 OpenJDK 8 时,当我的 Raspberry Pi 上停止播放声音时,我感到非常沮丧。
Editing the sound.properties for the OpenJDK solved my problem.
为 OpenJDK 编辑 sound.properties 解决了我的问题。
sudo vim /etc/java-8-openjdk/sound.properties
须藤 vim /etc/java-8-openjdk/sound.properties
Comment out the icedtea classpath configs:
注释掉 icedtea 类路径配置:
#javax.sound.sampled.Clip=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.Port=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.SourceDataLine=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.TargetDataLine=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider
#javax.sound.sampled.Clip=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.Port=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.SourceDataLine=org.classpath.icedtea .pulseaudio.PulseAudioMixerProvider #javax.sound.sampled.TargetDataLine=org.classpath.icedtea.pulseaudio.PulseAudioMixerProvider
Remove the comments from the sun classpath configs:
从 sun 类路径配置中删除注释:
javax.sound.sampled.Clip=com.sun.media.sound.DirectAudioDeviceProvider javax.sound.sampled.Port=com.sun.media.sound.PortMixerProvider javax.sound.sampled.SourceDataLine=com.sun.media.sound.DirectAudioDeviceProvider javax.sound.sampled.TargetDataLine=com.sun.media.sound.DirectAudioDeviceProvider
javax.sound.sampled.Clip=com.sun.media.sound.DirectAudioDeviceProvider javax.sound.sampled.Port=com.sun.media.sound.PortMixerProvider javax.sound.sampled.SourceDataLine=com.sun.media.sound. DirectAudioDeviceProvider javax.sound.sampled.TargetDataLine=com.sun.media.sound.DirectAudioDeviceProvider
Problem solved.
问题解决了。
In other words, you might have a different JDK between your Windows and Raspi, and they need different configuration.换句话说,您的 Windows 和 Raspi 之间可能有不同的 JDK,它们需要不同的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.