This commit fixes all critical bugs identified in the Piper engine that were causing server crashes, hung processes, resource leaks, and audio synthesis failures. ## Bug Fixes **Bug #1: Invalid --stdin CLI flag** - Removed non-existent --stdin flag from piper command - Piper reads stdin by default, flag was causing undefined behavior **Bug #2: Temp file race conditions** - Replaced NamedTemporaryFile context manager with tempfile.mkstemp() - Prevents file handle locking issues on some systems **Bug #3: Missing process timeouts** - Added asyncio.wait_for() with 30s timeout for piper synthesis - Added 60s timeout for ffmpeg conversion - Prevents hung processes from accumulating and exhausting memory **Bug #4: Orphaned temp files** - Implemented comprehensive temp file tracking list - Added cleanup in finally block to ensure all temp files are removed - Prevents /tmp/ from filling with orphaned audio files **Bug #5: FFmpeg error suppression** - Removed quiet=True from ffmpeg calls - Added capture_stdout and capture_stderr for full error context - Improved error messages with actual ffmpeg output **Bug #6: No config file validation** - Added upfront validation for .onnx and .onnx.json files - Validates speaker exists in config before synthesis - Provides clear error messages with available speakers list **Bug #7: Poor error context** - Added comprehensive logging with DEBUG/INFO/ERROR/WARNING levels - Error messages now include full command, model, speaker, text preview - Added success logging with file sizes and synthesis details ## New Features **Cache Versioning System** - Added CACHE_VERSION constant to automatically invalidate cache on bug fixes - Old cached files (with bugs) are automatically bypassed - Includes cleanup_old_cache_files() utility for removing stale cache - Version history documented in code comments **Configurable Timeouts** - PIPER_TIMEOUT_SECONDS: defaults to 30s (configurable via .env) - FFMPEG_TIMEOUT_SECONDS: defaults to 60s (configurable via .env) **Path Fixes** - Fixed audio file path validation in main.py (Bug causing 404s) - Updated AUDIO_CACHE_DIR to use relative paths for better portability **Documentation** - Added CLAUDE.md for future AI assistant context - Updated .env.example with new timeout configuration options ## Testing - ✅ Health check passed - ✅ Synthesis working correctly - ✅ No temp file leaks - ✅ No hung processes - ✅ Cache versioning prevents old buggy files from being served - ✅ Voice preview in wizard working correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
769 B
Python
30 lines
769 B
Python
"""
|
||
NovaAi – TTS-Engine-Hub
|
||
config.py
|
||
Version: v0.0.1
|
||
|
||
Description:
|
||
Centralized configuration management using pydantic-settings.
|
||
Loads settings from a .env file and environment variables.
|
||
"""
|
||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||
from typing import List, Set
|
||
|
||
class Settings(BaseSettings):
|
||
# Server Configuration
|
||
HOST: str = "0.0.0.0"
|
||
PORT: int = 8000
|
||
|
||
# Application Configuration
|
||
ACTIVE_ENGINES: Set[str] = {"piper"}
|
||
ASSET_DIR: str = "app/asset"
|
||
AUDIO_CACHE_DIR: str = "app/asset/audio"
|
||
|
||
# Piper Engine Timeouts (in seconds)
|
||
PIPER_TIMEOUT_SECONDS: int = 30
|
||
FFMPEG_TIMEOUT_SECONDS: int = 60
|
||
|
||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding='utf-8')
|
||
|
||
settings = Settings()
|