feat: add OpenAI-compatible Chatterbox TTS service

This commit is contained in:
vince 2026-08-08 23:10:07 +02:00
commit 38a2a48f28
9 changed files with 620 additions and 0 deletions

51
tests/test_synthesis.py Normal file
View file

@ -0,0 +1,51 @@
"""CUDA smoke coverage for the real Chatterbox synthesis path."""
from pathlib import Path
import pytest
import torch
import torchaudio
import app as chatterbox_app
def test_runtime_requirements_pin_chatterbox_cuda_contract():
requirements = {
line.strip()
for line in (Path(__file__).parents[1] / "requirements.txt").read_text().splitlines()
if line.strip() and not line.startswith("#")
}
assert {
"chatterbox-tts==0.1.7",
"torch==2.6.0",
"torchaudio==2.6.0",
"pydantic",
"setuptools<81",
"pytest",
} <= requirements
def test_chatterbox_generates_cuda_audio_from_reference_voice(tmp_path: Path):
"""The app wrapper returns real, decodable CUDA-synthesized WAV audio."""
if not torch.cuda.is_available():
pytest.skip("CUDA is unavailable")
reference = chatterbox_app.VOICES_DIR / "reference.wav"
assert reference.is_file(), "voices/reference.wav must be available for synthesis"
manager = chatterbox_app.model_manager
try:
wav_bytes = manager.generate("Chatterbox CUDA smoke test.", reference, 1.0)
finally:
manager.unload()
output_path = tmp_path / "chatterbox-cuda-smoke.wav"
output_path.write_bytes(wav_bytes)
waveform, sample_rate = torchaudio.load(output_path)
assert isinstance(waveform, torch.Tensor)
assert waveform.ndim == 2
assert waveform.shape[0] == 1
assert waveform.numel() > 0
assert sample_rate > 0
assert output_path.stat().st_size > 44