Monday, December 20, 2010

Work with sound jCaptcha in servlet, Part 1 - Setup FreeTTS

I have been working on jCaptcha recently. In addition to image captcha, I need to implement sound/audio captcha for 508 compliance. jCaptcha has an example here. However, I ran into two problems with the example. Firstly, there was an error when I used one instance (then changed captcha engine) for image and sound captcha. I ended up creating separate instances for image and sound captcha. Secondly, image and sound captcha don't share the same text sources so they are in fact two independent captchas. This is confusing since what the users see is not what they hear. But it seems to be a known problem and I have to live that. Otherwise, I would need to write my own implementation of WordGenerator to make sure to use the same text before passing it to captcha engine.

Note that jCaptcha depends on FreeTTS for sound. Here are the steps to setup FreeTTS for jCaptcha.
  1. Download and unzip jCaptcha. I used 1.2.2.
  2. Run jcaptcha.exe in /lib
  3. Copy all jars to your jCaptcha project classpath
  4. Set system property directly. This saves the trouble to mess with FreeTTS configuration.
            String voiceClasses = System.getProperty("freetts.voices"); // another one "freetts.voicesfile"
if (voiceClasses == null) {
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
voiceClasses = System.getProperty("freetts.voices");
}
log.info("freetts.voices:" + voiceClasses);

String bundle = "toddlist";
DictionaryReader reader = new FileDictionary(bundle);
WordGenerator generator = new DictionaryWordGenerator(reader);

SoundConfigurator soundConfig = new FreeTTSSoundConfigurator("kevin16", VOICE_PACKAGE, 1.0f, 100, 100);

WordToSound word2sound = new FreeTTSWordToSound(soundConfig, 3, 6);

CaptchaFactory[] factories = new CaptchaFactory[]{new GimpySoundFactory(generator, word2sound)};

CaptchaEngine captchaEngine = new GenericCaptchaEngine(factories);

instance = new GenericManageableCaptchaService(captchaEngine, 180,
180000, 75000);



With these limitations, my code compiled and passed the unit tests. Now this is the part one of the story. Stayed tuned for part 2.

1 comment:

  1. Hi ZL,

    I am working on Image/ Audio Captcha.Can you please provide me the code for that.

    It will be highly appreciable

    Thanks
    Saurabh

    ReplyDelete