Java UnsupportedAudioFileException

时间:2015-11-05 06:39:49

标签: java javasound

我正在阅读编解码器文件并使用Java和Java Sound转换为mp3 / wav文件,但收到以下错误。

错误

javax.sound.sampled.UnsupportedAudioFileException: file is not a supported file type
at javax.sound.sampled.AudioSystem.getAudioFileFormat(AudioSystem.java:1076)
at test.postingstackOverflow.main(postingstackOverflow.java:29)

代码

package test;

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

/**
 *
 * @author shankar
 */
public class postingstackOverflow {


    public static void main(String args[]){

         AudioFileFormat inputFileFormat=null;
         javax.sound.sampled.AudioFormat audioFormat =null;
         AudioInputStream encodedASI=null;
         AudioInputStream ais=null;

         try{

            inputFileFormat = AudioSystem.getAudioFileFormat(new File("/media/shankar/voip/Temp/JavaSound/1000.g711u"));
            ais = AudioSystem.getAudioInputStream(new File("/media/shankar/voip/Temp/JavaSound/1000.g711u"));
            audioFormat = ais.getFormat();
            encodedASI = AudioSystem.getAudioInputStream(javax.sound.sampled.AudioFormat.Encoding.ULAW, ais);

            int i = AudioSystem.write(encodedASI, AudioFileFormat.Type.WAVE, new File("/media/shankar/voip/Temp/JavaSound/converted.mp3"));

         }catch(Exception e){
                e.printStackTrace();

         }finally{

             try{
                    if(encodedASI!=null)
                        encodedASI.close();

                    if(ais!=null)
                        ais.close();
                    if(encodedASI!=null)
                        encodedASI.close();
                }catch(Exception expClose){
                    expClose.printStackTrace();
                }
       }//end finally
    }
}

谁能告诉我如何解读μ律文件?

0 个答案:

没有答案