Class AudioCaptchaGenerator

java.lang.Object
cloud.opencode.base.captcha.generator.AbstractCaptchaGenerator
cloud.opencode.base.captcha.generator.AudioCaptchaGenerator
All Implemented Interfaces:
CaptchaGenerator

public final class AudioCaptchaGenerator extends AbstractCaptchaGenerator implements CaptchaGenerator
Audio Captcha Generator - Generates audio CAPTCHA challenges as WAV files 音频验证码生成器 - 生成 WAV 格式的音频验证码挑战

This generator creates audio CAPTCHAs by synthesizing unique tone sequences for each character in the verification code. The generated audio includes background noise and interference tones to prevent automated recognition.

此生成器通过为验证码中的每个字符合成独特的音调序列来创建音频验证码。 生成的音频包含背景噪声和干扰音调以防止自动识别。

Features | 主要功能:

  • 16kHz 16-bit mono PCM WAV output - 16kHz 16位单声道 PCM WAV 输出
  • Unique tone sequences per character - 每个字符独特的音调序列
  • Background white noise (~15dB SNR) - 背景白噪声(约15dB信噪比)
  • Random interference tones - 随机干扰音调
  • Variable speed and frequency offsets - 可变速度和频率偏移

Usage Examples | 使用示例:

AudioCaptchaGenerator generator = new AudioCaptchaGenerator();
Captcha captcha = generator.generate(CaptchaConfig.builder()
    .length(4)
    .audioSpeedVariation(0.2f)
    .build());
byte[] wavData = captcha.imageData();

Security | 安全性:

  • Thread-safe: Yes (stateless, uses local SecureRandom) - 线程安全: 是(无状态,使用局部 SecureRandom)
  • Null-safe: No (config must not be null) - 空值安全: 否(config 不能为空)
Since:
JDK 25, opencode-base-captcha V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • AudioCaptchaGenerator

      public AudioCaptchaGenerator()
  • Method Details

    • getType

      public CaptchaType getType()
      Description copied from interface: CaptchaGenerator
      Gets the supported CAPTCHA type. 获取支持的验证码类型。
      Specified by:
      getType in interface CaptchaGenerator
      Returns:
      the CAPTCHA type | 验证码类型
    • generate

      public Captcha generate(CaptchaConfig config)
      Description copied from interface: CaptchaGenerator
      Generates a CAPTCHA with the specified configuration. 使用指定配置生成验证码。
      Specified by:
      generate in interface CaptchaGenerator
      Parameters:
      config - the configuration | 配置
      Returns:
      the generated CAPTCHA | 生成的验证码