voxi-lite / tests /fuzz.py
Joshuant's picture
Voxi Lite 0.2.0 (release candidate): server (HTTP + WebSocket streaming, telephony formats, OpenAI-style endpoint), output checks, PII-free logs, Dockerfile, pinned requirements, tests
b7ba9cf verified
Raw History Blame Contribute Delete
3.65 kB
"""Voxi Lite fuzz test: random mixed input (Devanagari, Tamil, Latin, digits, currency, IDs, punctuation, emoji,
odd whitespace) in every language mode and voice family. Pass: no crash (only the documented ValueError for text
over the length limit), and every non-empty output passes the audio checks after retries.
python tests/fuzz.py [--n 60] [--seed 0]
"""
import argparse
import json
import random
import sys
import traceback
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from voxi import MAX_CHARS, VoxiLite, audio_issue # noqa: E402
HI = "आपका ऑर्डर बिल रिफ़ंड पेमेंट कल शाम तक मिलेगा है नहीं कृपया धन्यवाद जी हाँ क्या कब कहाँ".split()
TA = "உங்கள் ஆர்டர் நாளை வரும் நன்றி தயவுசெய்து பணம் திருப்பி அனுப்பப்பட்டது".split()
EN = "your order refund payment will arrive tomorrow please thank you account OTP UPI KYC".split()
HIN = "aapka order kal tak aa jayega bill pay kar dijiye haan nahi theek hai shukriya".split()
ODD = ["₹1,250", "Rs. 99", "10:30", "31/12/2027", "98765 43210", "+91-98765-43210", "OTP 482913", "AB1234", "ABCPK1234F",
"2.5 lakh", "45%", "www.example.com", "help@example.com", "😊", "🎉🎉", "!!!", "...", "?", "।", "—", "(", ")", "\t",
"\n", " ", "&", "#123", "x" * 30, "1" * 25, "क्ष्त्र", "ௐ", "ॐ", "'", "\"", "​", "‍"]
def sample(rng):
pool = rng.choice([HI, TA, EN, HIN])
k = rng.randint(0, 25)
words = [rng.choice(pool) if rng.random() < 0.7 else rng.choice(ODD) for _ in range(k)]
if rng.random() < 0.05:
words = ["आपका ऑर्डर कल आएगा।"] * 200 # over the limit
return " ".join(words)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--n", type=int, default=60); ap.add_argument("--seed", type=int, default=0)
a = ap.parse_args()
rng = random.Random(a.seed)
tts = VoxiLite()
voices = ["payal", "arjun", "sanjana", "vishnu", "payal@happy", "arjun@sad-soft"]
crashes, bad_audio, too_long, empty, ok = [], 0, 0, 0, 0
for i in range(a.n):
text, lang, voice = sample(rng), rng.choice(["hi", "ta", "en", "hinglish", "te", "bn"]), rng.choice(voices)
try:
y = tts.synthesize(text, lang, voice)
if len(y) == 0:
empty += 1
else:
prepared, _ = tts.prepare(text, lang)
issue = audio_issue(y, prepared)
if issue:
bad_audio += 1
print(f"BAD_AUDIO {i} {lang} {voice} {issue}: {text[:60]!r}", flush=True)
else:
ok += 1
except ValueError as e:
if len(text) > MAX_CHARS:
too_long += 1
else:
crashes.append((i, lang, voice, text[:80], repr(e)))
except Exception as e: # noqa: BLE001
crashes.append((i, lang, voice, text[:80], repr(e)))
traceback.print_exc()
rep = {"n": a.n, "ok": ok, "empty": empty, "too_long_rejected": too_long, "bad_audio": bad_audio,
"crashes": len(crashes), "engine_stats": tts.stats}
for c in crashes:
print("CRASH", c, flush=True)
print("FUZZ", json.dumps(rep), flush=True)
sys.exit(0 if not crashes and not bad_audio else 1)
if __name__ == "__main__":
main()