save Audio Bytes To File - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

save Audio Bytes To File

Demo Code


//package com.java2s;
import javax.sound.sampled.*;
import java.io.*;

public class Main {
    public static void saveAudioBytesToFile(byte[] audio,
            AudioFormat audioFormat, AudioFileFormat.Type outputType,
            File outputFile) {//  www .  j a v a  2 s  .c  o m
        InputStream input = new ByteArrayInputStream(audio);
        AudioInputStream ais = new AudioInputStream(input, audioFormat,
                audio.length / audioFormat.getFrameSize());
        try {
            AudioSystem.write(ais, outputType, outputFile);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Related Tutorials