开发者

Converting Byte Array to Wav file [duplicate]

This question already has answers here: Convert audio stream to WAV byte array in Java witho开发者_开发百科ut temp file (5 answers) Closed 9 years ago.

After extensive research into the subject I have reached a brick wall.

All I want to do is add a collection of .wav files into a byte array, one after another, and output them all into one complete newly created .wav file. I extract all the .wav data into a byte array, skipping the .wav header and going straight for the data, then when it comes to writing it to the newly created .wav file I get an error like: Error1: javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream Error2: could not get audio input stream from input stream

The code is:

    try
    {
    String path = "*********";
    String path2 = path + "newFile.wav";

    File filePath = new File(path);
    File NewfilePath = new File(path2);

    String [] folderContent = filePath.list();

    int FileSize =  0;

    for(int i = 0; i < folderContent.length; i++)
        {
            RandomAccessFile raf = new RandomAccessFile(path + folderContent[i], "r");
            FileSize = FileSize + (int)raf.length();

        }

    byte[] FileBytes = new byte[FileSize];

    for(int i = 0; i < folderContent.length; i++)
        {
            RandomAccessFile raf = new RandomAccessFile(path + folderContent[i], "r");
            raf.skipBytes(44);
            raf.read(FileBytes);
            raf.close();

        }

    boolean success = NewfilePath.createNewFile();

    InputStream byteArray = new ByteArrayInputStream(FileBytes);

    AudioInputStream ais = AudioSystem.getAudioInputStream(byteArray);

    AudioSystem.write(ais, Type.WAVE, NewfilePath);

    }


Your byte array doesn't contain any header information which probably means that AutoSystem.write doesn't think it is really WAV data.

Can you create suitable header for your combined data?

Update: This question might hold the answer for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜