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. - Implemented platform detection to dynamically select between MLX and PyTorch based on the runtime environment. - Updated build process to include MLX-specific dependencies and configurations for macOS. - Refactored backend code to improve model loading and inference logic, accommodating backend-specific requirements. - Enhanced documentation to clarify backend selection and performance benefits for different platforms. - Streamlined installation instructions and troubleshooting guidance for MLX-related issues.
34 lines
776 B
Python
34 lines
776 B
Python
"""
|
|
Platform detection for backend selection.
|
|
"""
|
|
|
|
import platform
|
|
from typing import Literal
|
|
|
|
|
|
def is_apple_silicon() -> bool:
|
|
"""
|
|
Check if running on Apple Silicon (arm64 macOS).
|
|
|
|
Returns:
|
|
True if on Apple Silicon, False otherwise
|
|
"""
|
|
return platform.system() == "Darwin" and platform.machine() == "arm64"
|
|
|
|
|
|
def get_backend_type() -> Literal["mlx", "pytorch"]:
|
|
"""
|
|
Detect the best backend for the current platform.
|
|
|
|
Returns:
|
|
"mlx" on Apple Silicon (if MLX is available), "pytorch" otherwise
|
|
"""
|
|
if is_apple_silicon():
|
|
try:
|
|
import mlx
|
|
return "mlx"
|
|
except ImportError:
|
|
# MLX not installed, fallback to PyTorch
|
|
return "pytorch"
|
|
return "pytorch"
|