mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-15 04:40:40 -07:00
- Added support for MLX backend on Apple Silicon, enabling optimized performance for TTS and STT tasks. - Updated release workflow to include MLX-specific dependencies and configurations for macOS platforms. - Refactored backend code to dynamically select between MLX and PyTorch based on the runtime environment. - Enhanced model loading and inference logic to accommodate backend-specific requirements, including updated model IDs and hidden imports. - Improved health check and model status reporting to reflect the active backend type. - Streamlined caching mechanisms to support both backend types, ensuring compatibility and performance.
43 lines
1007 B
Python
43 lines
1007 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()
|
|
|
|
|
|
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()
|