简体   繁体   English

如何使用Java AudioSystem.write保存多于一个字节的数组

[英]How to save more that one byte array using Java AudioSystem.write

    public void run(){
            AudioInputStream audioInputStream= new AudioInputStream(pis,audioFormat,samlpesCount);
            try {

                 AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, file);

            } catch (Exception e) {
                e.printStackTrace();
            } finally{
                try {
                    pis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

pis is a PipedInputStream , through I send byte arrays with data. pisPipedInputStream ,通过我发送带有数据的字节数组。 This way I can save only 1 byte array of data. 这样,我只能保存1个字节的数据数组。 It don't waits for next piece of data. 它不等待下一个数据。 Would you advice me something? 你能给我一些建议吗?

You could use a WaveFileWriter like so: 您可以像这样使用WaveFileWriter:

InputStream in = ...;
OutputStream out = ...;

AudioInputStream in = AudioSystem.getAudioInputStream(in);

WaveFileWriter writer = new WaveFileWriter();
writer.write(in, AudioFileFormat.Type.WAVE, outStream);

我有解决方案: samlpesCount必须是总样本计数,不仅是一个容器的大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java AudioInputStream AudioSystem.write到管道长度错误 - java AudioInputStream AudioSystem.write to pipe length error AudioSystem.write(input, AudioFileFormat.Type.WAVE, file) 产生损坏的 WAVE 文件。 RIFF 长度无效 - AudioSystem.write(input, AudioFileFormat.Type.WAVE, file) produces a corrupt WAVE file. Invalid RIFF length 使用Tritonus AudioSystem:将PCM byte []数组转换为mp3 byte []数组 - Using Tritonus AudioSystem: Convert PCM byte[] array to mp3 byte[] array 如何在java中将字节数组保存到二进制文件中 - How to save byte array into an binary file in java 如何在Swift中编写Java字节数组 - How to write Java byte array in Swift 如何将转换为字节数组的文本文件内容写入 java 中的另一个文件内容 - How to write a converted to byte array text file content into another one in java RandomAccessFile:循环写入(字节)或写入(字节数组),哪个更有效? - RandomAccessFile: write(byte) in a loop or write(byte array), whats more effiecient? 在java中将字节数组写入文件 - Write byte array to file in java 如何在Java中使用AudioSystem播放音乐(.mp3)? - How to play Music (.mp3) in Java with AudioSystem? 使用java在postgres中将图像保存和检索为字节数组 - Image save and retrieve as byte array in postgres using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM