Customizing Your Audio CAPTCHAs

Audio CAPTCHAs allow you to gracefully handle visually-impaired users. These CAPTCHAs are generated similarly to image CAPTCHAs, using a Builder. Also like Captcha.Builder, hooks are provided to allow for developers to provide their own behavior.

The Builder

Audio CAPTCHAs are generated using AudioCaptcha.Builder:

1 AudioCaptcha ac = new AudioCaptcha.Builder()
2     .addAnswer()
3     .addNoise()
4     .build(); // Required

The default behavior here is to generate an audio CAPTCHA that is five spoken (English) numbers, from a list of voices. For example, the above would generate something like the following:

The voices are picked at random from the /sounds/en/numbers directory in the JAR file. If you would like to provide your own files for the numbers, you can do so:

 1 Map<Integer, String[]> voicesMap = new HashMap<Integer, String[]>();
 2 String[] fileLocs0 = {"/my_sounds/0-loud.wav", "/my_sounds/0-quiet.wav"};
 3 String[] fileLocs1 = {"/my_sounds/1-loud.wav", "/my_sounds/1-quiet.wav"};
 4 ...
 5 voicesMap.put(0, fileLocs0);
 6 voicesMap.put(1, fileLocs1);
 7 VoiceProducer vProd = new RandomNumberVoiceProducer(voicesMap);
 8 
 9 AudioCaptcha ac = new AudioCaptcha.Builder()
10     .addAnswer()
11     .addVoice(vProd)
12     .addNoise()
13     .build(); // Required

You can also provide your own noise:

1 String[] noiseFiles = {"/my_sounds/my_noise1.wav", "/my_sounds/my_noise2.wav"};
2 NoiseProducer nProd = new NoiseProducer(noiseFiles);
3 
4 AudioCaptcha ac = new AudioCaptcha.Builder()
5     .addAnswer()
6     .addVoice()
7     .addNoise(nProd)
8     .build(); // Required

Home

Download SimpleCaptcha

Installing

Customizing

Example Applications

Source

Javadocs