SimpleCaptcha and wav playback

北慕城南 提交于 2019-12-05 06:34:25

问题


Our client is using SimpleCaptcha. My understanding is that SimpleCaptcha is able to produce audio captchas in WAVE format (.wav). Later these CAPTCHA-s are played back using the HTML5 audio tag, something like this:

<audio controls="controls" autoplay>
    <source src="captcha.wav" />
</audio>

Of course this is not cross browser compatible and one of the reasons is the WAVE format. This link suggests that IE9 supports only MP3 while most other browsers are fine with OGG and WAVE. Further MP3 is a patented to... to Fraunhofer?

Note: our back-end is Java based.

My question is what is the best fallback that we may offer to clients that do not support either the WAVE format (e.g. IE9) or the HTML5 audio tag at all? Due to patent issues I guess that dynamic conversion to mp3 on server side is not an option. Further I do not know any java library that may do this... I have seen nice solutions like jPlayer but they say that "For cross-browser support, a format must be supplied that works in both HTML5 and Flash.", i.e. mp3, mp4. I didn't find any reliable flash based WAVE players too.


回答1:


With help from others in the community, I have created a Flash button that can stream WAV files from the server to the client. It is distributed with Securimage PHP Captcha for streaming audio CAPTCHAs to the client.

You could simply take this Flash button, or download and modify the Flash source code to create your own custom one based on the same code.

You could use it as a fallback for when HTML5 audio isn't available.

Example usage would be:

<object type="application/x-shockwave-flash"
        data="securimage_play.swf?audio_file=/PATH/TO/AUDIO.wav"
        width="32" height="32">
    <param name="movie" value="securimage_play.swf?audio_file=/PATH/TO/AUDIO.wav" />
</object>

You can pass these additional options to securimage_play.swf:

  • bgcol: background-color of the Flash button
  • icon_file: URL to a png image to display as the icon on the Flash button

On a side note, I do find Microsoft's decision to not support WAV audio in the <audio> tag strange, especially since they pioneered WAV format with IBM. Yes WAV files are bigger than the other compressed audio formats they support, but bandwidth is also increasing to the point where it doesn't matter.

Hope that helps. Let me know if you try to implement it and have any questions. You can see a demo of the audio streaming here.




回答2:


I think the help of @drew010 with their button was awesome!! Thank you.

To solve the same problem with rate frequency support between SimpleCaptcha (16000Hz) and supported audio for flash player (11025Hz) I've used an alternative solution instead change simplecaptcha source or try solve it at flash programming.

My captcha implementation has a custom audio captcha servlet (as supported by simplecaptcha), so I used the tip provided by @Claude in this post using tritonus lib to convert audio sample rate. The piece of code looks like that:

    AudioFormat outDataFormat = new AudioFormat((float) 11025.0, (int) 16, (int) 1, true, false);
    AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(outDataFormat, audioCapthca.getChallenge().getAudioInputStream());

My captcha servlet code below:

public class AudioCaptchaServlet extends HttpServlet {

    @Override protected void doGet(HttpServletRequest req,
            HttpServletResponse resp) throws ServletException, IOException {

        Map<Integer, String[]> voicesMap = new HashMap<Integer, String[]>();
        String[] fileLocs0 = {"/captcha/pt_BR/0.wav"};
        String[] fileLocs9 = {"/captcha/pt_BR/1.wav"};
        (...)

        voicesMap.put(0, fileLocs0);
        voicesMap.put(1, fileLocs1);
        (...)

        VoiceProducer voiceProducer = new RandomNumberVoiceProducer(voicesMap);

        AudioCaptcha ac = new AudioCaptcha.Builder()
            .addAnswer()
            .addNoise()
            .addVoice(voiceProducer)
            .build();

        req.getSession().setAttribute(AudioCaptcha.NAME, ac.getAnswer());

        //Converte Sons com bitrate de 16000Hz (simplecaptcha) para 11025Hz (suportada pelo flash player)
        AudioFormat outDataFormat = new AudioFormat((float) 11025.0, (int) 16, (int) 1, true, false);
        AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(outDataFormat, ac.getChallenge().getAudioInputStream());

        CaptchaServletUtil.writeAudio(resp, new Sample(lowResAIS));
    }

    @Override protected void doPost(HttpServletRequest req,
            HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}



回答3:


If any one still looking for It. Here is my code. It worked in all browsers for me.

<audio controls id="audioCaptcha">
    <source src="audio.wav" type='audio/wav' height="50px" width="100px"/>
    <embed src="audio.wav" type='audio/wav' autoplay="false" height="50px" width="100px"/>
</audio>


来源:https://stackoverflow.com/questions/11758462/simplecaptcha-and-wav-playback

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