package itn.com.cmm.captcha; import java.util.HashMap; import java.util.Map; import nl.captcha.audio.Sample; import nl.captcha.audio.producer.VoiceProducer; import nl.captcha.util.FileUtil; public class SetKorVoiceProducer implements VoiceProducer { private static final Map DEFAULT_VOICES_MAP; static { DEFAULT_VOICES_MAP = new HashMap(); StringBuilder sb; for (int i = 0; i < 10; i++) { sb = new StringBuilder("/sounds/ko/numbers/"); sb.append(i); sb.append(".wav"); DEFAULT_VOICES_MAP.put(i, sb.toString()); } } private final Map _voices; public SetKorVoiceProducer() { this(DEFAULT_VOICES_MAP); } public SetKorVoiceProducer(Map voices) { _voices = voices; } @Override public Sample getVocalization(char num) { try { Integer.parseInt(num + ""); } catch (NumberFormatException e) { throw new IllegalArgumentException("Expected to be a number, got '" + num + "' instead.",e); } int idx = Integer.parseInt(num + ""); String filename = _voices.get(idx); return FileUtil.readSample(filename); } }