从inputStream写的wav文件不可播放

时间:2017-09-13 10:04:43

标签: java wav file-conversion

我用wav文件格式写inputStream,正在写文件但是当我尝试打开文件时它没有播放,我认为它已损坏。如何查看或调试我的不足之处。任何帮助表示赞赏。

    InputStream speechStream= null;
    InputStreamResource inputStreamResource=null;   

    try{
        speechStream=quikWitService.getPollyTextToSpeech(voiceId,text,outputFormat);
        inputStreamResource= new InputStreamResource(speechStream);




        File audioFile = new File("D:/Tomcat/apache-tomcat-8.5.20/webapps/QuikWit/hello.wav");     

        try {
            byte[] buffer = new byte[2 * 1024];
            int readBytes;
            FileOutputStream outputStream = new FileOutputStream(audioFile);
            try (InputStream in = speechStream){
                    while ((readBytes = in.read(buffer)) > 0) {
                        outputStream.write(buffer, 0, readBytes);
                   }
               }
            outputStream.close();
        }catch(Exception exception)
        {
            System.out.println("Couldn't process the audio");
        }
        System.out.println("Success");      




    }
    catch(Exception e){
        logger.error(e);
        logger.debug(e.getStackTrace());
    }

0 个答案:

没有答案