feat(voice/clone): support MP3 and other audio formats for reference voices (#20)

## Summary
- Adds support for MP3, FLAC, OGG, and other audio formats when
uploading reference voices for cloning
- Replace WAV-only `audio_read()` with a `soundfile`-based
implementation
- Update web UI file picker to accept multiple audio formats

## Changes
- `pocket_tts/data/audio.py`: Use `soundfile` library instead of
Python's `wave` module
- `pocket_tts/main.py`: Preserve original file extension in temp files
for format detection
- `pocket_tts/main.py`: Add missing `truncate=True` to CLI generate
command
- `pocket_tts/static/index.html`: Update file input to accept
`.wav,.mp3,.flac,.ogg,.m4a,audio/*`
- `pyproject.toml`: Add `soundfile>=0.12.0` dependency

## Tested
- [x] Upload a WAV file as reference voice and generate speech
- [x] Upload an MP3 file as reference voice and generate speech
- [x] Upload a FLAC file as reference voice and generate speech
- [x] Verify CLI `--voice` option works with MP3 files

---------

Co-authored-by: Gabriel de Marmiesse <gabrieldemarmiesse@gmail.com>
Co-authored-by: Václav Volhejn <8401624+vvolhejn@users.noreply.github.com>
This commit is contained in:
Und3rf10w
2026-01-20 10:12:50 +01:00
committed by GitHub
co-authored by Gabriel de Marmiesse Václav Volhejn
parent 6f9dd250c2
commit bedd1c4098
5 changed files with 155 additions and 15 deletions
+4 -3
View File
@@ -142,11 +142,12 @@ def text_to_speech(
raise HTTPException(
status_code=400, detail="voice_url must start with http://, https://, or hf://"
)
model_state = tts_model._cached_get_state_for_audio_prompt(voice_url, truncate=True)
model_state = tts_model._cached_get_state_for_audio_prompt(voice_url)
logging.warning("Using voice from URL: %s", voice_url)
elif voice_wav is not None:
# Use uploaded voice file
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
# Use uploaded voice file - preserve extension for format detection
suffix = Path(voice_wav.filename).suffix if voice_wav.filename else ".wav"
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
content = voice_wav.file.read()
temp_file.write(content)
temp_file.flush()