Tag: javasound

资源.wav中的Javaexception读取流

我猜我的代码没问题,我的.jar文件也可以使用里面的.wav。但是当我尝试使用getResourceAsStream加载它时,我得到一个错误.. 这是我的错误: java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at operation.MainWindowOperations.prepareAudio(MainWindowOperations.java :92) at operation.MainWindowOperations.(MainWindowOperations.java:81) at graphics.LaunchGraphics.(LaunchGraphics.java:25) at run.RunApp.main(RunApp.java:14) 这是我的代码: private void prepareAudio() { try { InputStream is = this.getClass().getClassLoader().getResourceAsStream(“beep.wav”); inputStream = AudioSystem.getAudioInputStream(is); clip = AudioSystem.getClip(); clip.open(inputStream); } catch (Exception ex) { ex.printStackTrace(); } } 有人能帮我吗? […]

模拟麦克风输入

我正在尝试编写一个读取wav文件的小程序,并将输出发送,就像它来自我的麦克风一样。 不幸的是,我对声音API没有多少经验。 背景:我基本上想要实现的是一个程序,当我在语音聊天(即Teamspeak,Ventrilo)时播放声音。 为了让它现在起作用,我必须将录音设备切换到“你听到了什么”,播放声音,然后切换回麦克风。 该程序应模拟麦克风的输入。 到目前为止,我只能播放声音。 我想我只需要一个不同的SourceLine? 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 { […]

使用Java将音频从44.1kHz下采样到16kHz

我有一个应用程序,它记录来自用户麦克风的语音样本,并将其上传到服务器,然后服务器用它做一些事情。 看来我必须使用以下参数进行记录以避免IllegalArgumentException : Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; float sampleRate = 44100.0F; int sampleSizeInBits = 16; int channels = 2; int frameSize = 4; float frameRate = 44100.0F; boolean bigEndian = false; 但是我需要将它记录在16khz,而不是44.1,(sampleRate和framerate都是,我假设)并且它必须是单声道(1声道)。 PCM签名也是强制性的,所以这很好。 (服务器非常挑剔,我无法对其进行任何更改。)如何使用Java进行转换? 我通过HttpClient将音频文件作为Filebody提交给servlet,将其保存在服务器上,然后进行处理。

理解AudioFormat,AudioInputStream和start方法的构造函数

我曾尝试编写播放声音文件的程序但到目前为止都没有成功。 我无法理解代码的某些部分: InputStream is = new FileInputStream(“sound file”); AudioFormat af = new AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian); // I don’t understand it’s constructor long length ; // length in sample frames // how cani i know the length of frames ? AudioInputStream ais = new AudioInputStream( is , af , […]

如何使用Xuggler获取用于编码的音频

我正在编写一个记录屏幕和音频的应用程序。 虽然屏幕录制效果很好,但我很难使用JDK库获取原始音频。 这是代码: try { // Now, we’re going to loop long startTime = System.nanoTime(); System.out.println(“Encoding Image…..”); while (!Thread.currentThread().isInterrupted()) { // take the screen shot BufferedImage screen = robot.createScreenCapture(screenBounds); // convert to the right image type BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR); // encode the image writer.encodeVideo(0, bgrScreen, System.nanoTime() – startTime, TimeUnit.NANOSECONDS); /* Need to get […]

如何跟踪音频播放位置?

我创建了一个线程,通过将其转换为字节数组来播放Java中的mp3文件。 我想知道我是否可以在播放mp3时跟踪当前的播放位置。 首先,我设置了我的音乐流: try { AudioInputStream in = AudioSystem.getAudioInputStream(file); musicInputStream = AudioSystem.getAudioInputStream(MUSIC_FORMAT, in); DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, MUSIC_FORMAT); musicDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo); musicDataLine.open(MUSIC_FORMAT); musicDataLine.start(); startMusicThread(); } catch(Exception e) { e.printStackTrace(); } 接下来,我的音乐线程如下所示: private class MusicThread extends Thread { byte musicBuffer[] = new byte[BUFFER_SIZE]; public void run() { try { int musicCount = 0; while(writeOutput){ […]

剪辑在Java中播放带有坏滞后的WAV文件

我编写了一个代码来读取WAV文件(大小约为80 MB)并播放它。 问题是声音播放严重(极端滞后)。 你能告诉我这是什么问题吗? 这是我的代码:(我在Jframe构造函数中调用doPlay函数) private void doPlay(final String path) { try { stopPlay(); InputStream is = new FileInputStream(path); InputStream bufferedIn = new BufferedInputStream(is); AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn); AudioFormat format = ais.getFormat(); // this is the value of format. // PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian DataLine.Info info = new DataLine.Info(Clip.class, format); […]

用Java打开/关闭计算机音量?

我想用一个命令上下调整计算机的主音量(100%/ 0%)。 我看到我可以使用FloatControl ,但我不知道如何使用它。

MIDI初学者 – 需要播放一个音符

我不太了解Java的MIDIfunction。 事实上,它完全让我感到困惑。 然而,我想要做的只是构建一个简单的应用程序,它将播放一个音符。 如何使用Java Sound播放单个MIDI音符? 网上对此的支持几乎不存在,我完全不知所措。

Java检测音频文件(mp3)

我有这个代码读取一个mp3文件 import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; public class Sound { public static void main(String[] args) { File sampleFile = new File(“test.mp3”); try { AudioSystem.getAudioFileFormat(sampleFile); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 这里的问题是它返回文件不支持exception,这里的文件是一个mp3文件。 Java不支持mp3文件? 如果是这样,其他人validation音频文件是什么?(如ogg,wav)