mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-18 06:10:43 -07:00
Add Tauri integration and server management features. Introduced auto-start functionality for the bundled server in Tauri environment, added configuration management for data directories, and refactored backend components to utilize the new config module. Updated dependencies and improved project structure for better organization.
This commit is contained in:
+19
-16
@@ -5,12 +5,15 @@ Voice prompt caching utilities.
|
||||
import hashlib
|
||||
import torch
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
import soundfile as sf
|
||||
from typing import Optional
|
||||
|
||||
from .. import config
|
||||
|
||||
|
||||
_cache_dir = Path("data/cache")
|
||||
_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
def _get_cache_dir() -> Path:
|
||||
"""Get cache directory from config."""
|
||||
return config.get_cache_dir()
|
||||
|
||||
|
||||
# In-memory cache
|
||||
_memory_cache: dict[str, torch.Tensor] = {}
|
||||
@@ -19,21 +22,21 @@ _memory_cache: dict[str, torch.Tensor] = {}
|
||||
def get_cache_key(audio_path: str, reference_text: str) -> str:
|
||||
"""
|
||||
Generate cache key from audio file and reference text.
|
||||
|
||||
|
||||
Args:
|
||||
audio_path: Path to audio file
|
||||
reference_text: Reference text
|
||||
|
||||
|
||||
Returns:
|
||||
Cache key (MD5 hash)
|
||||
"""
|
||||
# Read audio file
|
||||
with open(audio_path, "rb") as f:
|
||||
audio_bytes = f.read()
|
||||
|
||||
|
||||
# Combine audio bytes and text
|
||||
combined = audio_bytes + reference_text.encode("utf-8")
|
||||
|
||||
|
||||
# Generate hash
|
||||
return hashlib.md5(combined).hexdigest()
|
||||
|
||||
@@ -43,19 +46,19 @@ def get_cached_voice_prompt(
|
||||
) -> Optional[torch.Tensor]:
|
||||
"""
|
||||
Get cached voice prompt if available.
|
||||
|
||||
|
||||
Args:
|
||||
cache_key: Cache key
|
||||
|
||||
|
||||
Returns:
|
||||
Cached voice prompt tensor or None
|
||||
"""
|
||||
# Check in-memory cache
|
||||
if cache_key in _memory_cache:
|
||||
return _memory_cache[cache_key]
|
||||
|
||||
|
||||
# Check disk cache
|
||||
cache_file = _cache_dir / f"{cache_key}.prompt"
|
||||
cache_file = _get_cache_dir() / f"{cache_key}.prompt"
|
||||
if cache_file.exists():
|
||||
try:
|
||||
prompt = torch.load(cache_file)
|
||||
@@ -64,7 +67,7 @@ def get_cached_voice_prompt(
|
||||
except Exception:
|
||||
# Cache file corrupted, delete it
|
||||
cache_file.unlink()
|
||||
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -74,14 +77,14 @@ def cache_voice_prompt(
|
||||
) -> None:
|
||||
"""
|
||||
Cache voice prompt to memory and disk.
|
||||
|
||||
|
||||
Args:
|
||||
cache_key: Cache key
|
||||
voice_prompt: Voice prompt tensor
|
||||
"""
|
||||
# Store in memory
|
||||
_memory_cache[cache_key] = voice_prompt
|
||||
|
||||
|
||||
# Store on disk
|
||||
cache_file = _cache_dir / f"{cache_key}.prompt"
|
||||
cache_file = _get_cache_dir() / f"{cache_key}.prompt"
|
||||
torch.save(voice_prompt, cache_file)
|
||||
|
||||
Reference in New Issue
Block a user