1

I need to save the file to play Simplecaptcha voice file on IOS and succeeded in saving the file in a folder I want.

But I tried to play the wav file in the folder(double click), It wasn't replayed.

Please help me

public static void saveAudio(final HttpServletRequest request, final HttpServletResponse response, final Sample sample) {

        String fileName = request.getParameter("fileName");
        try {

            final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
            AudioSystem.write(sample.getAudioInputStream(), AudioFileFormat.Type.WAVE, baos);

            byte audioData[] = baos.toByteArray();

            AudioFormat af = new AudioFormat(16000.0F, 16, 1,true, false); // simplecaptcha default setting 
            ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
            AudioInputStream ais = new AudioInputStream(bais, af , audioData.length);   
            AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("/audio/"+fileName+".wav")); 

        } catch (IOException e) {
            System.out.println(e);

        }      
    }
Adam
  • 2,726
  • 1
  • 9
  • 22
Sophia LEE
  • 11
  • 1

0 Answers0