mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-15 12:50:42 -07:00
Move 9 business-logic modules from the backend root into services/: channels, effects, history, profiles, stories, versions, export_import, transcribe, tts. Move platform_detect.py into utils/. Backend root now contains only infrastructure (app, main, config, server, models, build_binary) and docs. All 94 routes verified.
35 lines
767 B
Python
35 lines
767 B
Python
"""
|
|
TTS inference module - delegates to backend abstraction layer.
|
|
"""
|
|
|
|
from typing import Optional
|
|
import numpy as np
|
|
import io
|
|
import soundfile as sf
|
|
|
|
from ..backends import get_tts_backend, TTSBackend
|
|
|
|
|
|
def get_tts_model() -> TTSBackend:
|
|
"""
|
|
Get TTS backend instance (MLX or PyTorch based on platform).
|
|
|
|
Returns:
|
|
TTS backend instance
|
|
"""
|
|
return get_tts_backend()
|
|
|
|
|
|
def unload_tts_model():
|
|
"""Unload TTS model to free memory."""
|
|
backend = get_tts_backend()
|
|
backend.unload_model()
|
|
|
|
|
|
def audio_to_wav_bytes(audio: np.ndarray, sample_rate: int) -> bytes:
|
|
"""Convert audio array to WAV bytes."""
|
|
buffer = io.BytesIO()
|
|
sf.write(buffer, audio, sample_rate, format="WAV")
|
|
buffer.seek(0)
|
|
return buffer.read()
|