how to do framing for a given wave file in java

百般思念 提交于 2020-01-17 06:16:12

问题


i want to split my audio file(.wav format) in frames of 32 milliseconds each sampling frequn-16khz,number of channels-1(mono),pcm signal, sample size=93638. I am using the following code for reading my wave file which give an array which is stored in data2 array.Can some one tell me how to proceed from this -:

import java.io.ByteArrayOutputStream;
import java.io.File;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

public class AudioFiles 
{
public static void main(String[] args) 
{
    String file = "D:/p.wav";
    int i;
    AudioFiles afiles = new AudioFiles();
    byte[] data2 = afiles.readWAVAudioFileData(file);
    for(i=0;i<data2.length;i++)
    {
    System.out.format("\t"+data2[i]);

    }
    System.out.printf("\n%d",data2.length);
}

public byte[] readWAVAudioFileData(final String filePath)
{
    byte[] data = null;
    try {
        final ByteArrayOutputStream baout = new ByteArrayOutputStream();
        final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(filePath));

        AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, baout);
        audioInputStream.close();
        baout.close();
        data = baout.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return data;
}

}


回答1:


At 16kHz sample rate you'll have 16 samples per millisecond. Therefore, each 32ms frame would be 32*16=512 mono samples. Multiply by the number of bytes-per-sample (typically 2 or 4) and that will be the number of bytes per frame.



来源:https://stackoverflow.com/questions/22389143/how-to-do-framing-for-a-given-wave-file-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!