Spaces:
Running
Running
Commit
·
6f1d384
1
Parent(s):
2acc39d
updated the path to the that was casing permission issues in entire app
Browse files- app/api/routes.py +8 -3
- app/utils/voice_manager.py +10 -5
- app/voice_cloning.py +2 -1
- app/voice_enhancement.py +5 -5
- app/voice_memory.py +3 -2
app/api/routes.py
CHANGED
@@ -16,7 +16,7 @@ import numpy as np
|
|
16 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, Body, Response, Query
|
17 |
from fastapi.responses import StreamingResponse
|
18 |
from app.api.schemas import SpeechRequest, ResponseFormat, Voice
|
19 |
-
from app.models import Segment
|
20 |
from app.api.streaming import AudioChunker
|
21 |
from app.prompt_engineering import split_into_segments
|
22 |
|
@@ -24,6 +24,11 @@ from app.prompt_engineering import split_into_segments
|
|
24 |
logger = logging.getLogger(__name__)
|
25 |
router = APIRouter()
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
# Mapping of response_format to MIME types
|
28 |
MIME_TYPES = {
|
29 |
"mp3": "audio/mpeg",
|
@@ -433,7 +438,7 @@ async def format_audio(audio, response_format, sample_rate, app_state):
|
|
433 |
# Generate a hash of the audio tensor for caching
|
434 |
audio_hash = hashlib.md5(audio.cpu().numpy().tobytes()).hexdigest()
|
435 |
cache_key = f"{audio_hash}_{response_format}"
|
436 |
-
cache_dir = getattr(app_state, "audio_cache_dir",
|
437 |
os.makedirs(cache_dir, exist_ok=True)
|
438 |
cache_path = os.path.join(cache_dir, f"{cache_key}")
|
439 |
|
@@ -534,7 +539,7 @@ async def format_audio(audio, response_format, sample_rate, app_state):
|
|
534 |
# Store in cache if enabled
|
535 |
if cache_enabled and cache_key:
|
536 |
try:
|
537 |
-
cache_path = os.path.join(getattr(app_state, "audio_cache_dir",
|
538 |
with open(cache_path, "wb") as f:
|
539 |
f.write(response_data)
|
540 |
logger.debug(f"Cached {response_format} audio with key: {cache_key}")
|
|
|
16 |
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks, Body, Response, Query
|
17 |
from fastapi.responses import StreamingResponse
|
18 |
from app.api.schemas import SpeechRequest, ResponseFormat, Voice
|
19 |
+
from app.models import Segment, TTSRequest, TTSResponse, StreamRequest
|
20 |
from app.api.streaming import AudioChunker
|
21 |
from app.prompt_engineering import split_into_segments
|
22 |
|
|
|
24 |
logger = logging.getLogger(__name__)
|
25 |
router = APIRouter()
|
26 |
|
27 |
+
# Constants
|
28 |
+
APP_DIR = os.path.join(os.environ['HOME'], 'app')
|
29 |
+
AUDIO_CACHE_DIR = os.path.join(APP_DIR, "audio_cache")
|
30 |
+
os.makedirs(AUDIO_CACHE_DIR, exist_ok=True)
|
31 |
+
|
32 |
# Mapping of response_format to MIME types
|
33 |
MIME_TYPES = {
|
34 |
"mp3": "audio/mpeg",
|
|
|
438 |
# Generate a hash of the audio tensor for caching
|
439 |
audio_hash = hashlib.md5(audio.cpu().numpy().tobytes()).hexdigest()
|
440 |
cache_key = f"{audio_hash}_{response_format}"
|
441 |
+
cache_dir = getattr(app_state, "audio_cache_dir", AUDIO_CACHE_DIR)
|
442 |
os.makedirs(cache_dir, exist_ok=True)
|
443 |
cache_path = os.path.join(cache_dir, f"{cache_key}")
|
444 |
|
|
|
539 |
# Store in cache if enabled
|
540 |
if cache_enabled and cache_key:
|
541 |
try:
|
542 |
+
cache_path = os.path.join(getattr(app_state, "audio_cache_dir", AUDIO_CACHE_DIR), f"{cache_key}")
|
543 |
with open(cache_path, "wb") as f:
|
544 |
f.write(response_data)
|
545 |
logger.debug(f"Cached {response_format} audio with key: {cache_key}")
|
app/utils/voice_manager.py
CHANGED
@@ -8,18 +8,23 @@ from typing import Dict, List, Optional, Any
|
|
8 |
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
# Ensure directories exist
|
17 |
os.makedirs(VOICE_REFERENCES_DIR, exist_ok=True)
|
18 |
os.makedirs(VOICE_PROFILES_DIR, exist_ok=True)
|
19 |
os.makedirs(VOICE_MEMORIES_DIR, exist_ok=True)
|
|
|
20 |
|
21 |
-
def backup_voice_data(backup_dir: str =
|
22 |
"""Create a backup of all voice data."""
|
|
|
|
|
23 |
os.makedirs(backup_dir, exist_ok=True)
|
24 |
timestamp = torch.datetime.now().strftime("%Y%m%d_%H%M%S")
|
25 |
backup_path = os.path.join(backup_dir, f"voice_backup_{timestamp}")
|
|
|
8 |
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
+
# Constants
|
12 |
+
APP_DIR = os.path.join(os.environ['HOME'], 'app')
|
13 |
+
VOICE_REFERENCES_DIR = os.path.join(APP_DIR, "voice_references")
|
14 |
+
VOICE_PROFILES_DIR = os.path.join(APP_DIR, "voice_profiles")
|
15 |
+
VOICE_MEMORIES_DIR = os.path.join(APP_DIR, "voice_memories")
|
16 |
+
VOICE_BACKUPS_DIR = os.path.join(APP_DIR, "voice_backups")
|
17 |
|
18 |
# Ensure directories exist
|
19 |
os.makedirs(VOICE_REFERENCES_DIR, exist_ok=True)
|
20 |
os.makedirs(VOICE_PROFILES_DIR, exist_ok=True)
|
21 |
os.makedirs(VOICE_MEMORIES_DIR, exist_ok=True)
|
22 |
+
os.makedirs(VOICE_BACKUPS_DIR, exist_ok=True)
|
23 |
|
24 |
+
def backup_voice_data(backup_dir: str = None):
|
25 |
"""Create a backup of all voice data."""
|
26 |
+
if backup_dir is None:
|
27 |
+
backup_dir = VOICE_BACKUPS_DIR
|
28 |
os.makedirs(backup_dir, exist_ok=True)
|
29 |
timestamp = torch.datetime.now().strftime("%Y%m%d_%H%M%S")
|
30 |
backup_path = os.path.join(backup_dir, f"voice_backup_{timestamp}")
|
app/voice_cloning.py
CHANGED
@@ -27,7 +27,8 @@ from app.models import Segment
|
|
27 |
logger = logging.getLogger(__name__)
|
28 |
|
29 |
# Directory for storing cloned voice data
|
30 |
-
|
|
|
31 |
os.makedirs(CLONED_VOICES_DIR, exist_ok=True)
|
32 |
|
33 |
class ClonedVoice(BaseModel):
|
|
|
27 |
logger = logging.getLogger(__name__)
|
28 |
|
29 |
# Directory for storing cloned voice data
|
30 |
+
APP_DIR = os.path.join(os.environ['HOME'], 'app')
|
31 |
+
CLONED_VOICES_DIR = os.path.join(APP_DIR, "cloned_voices")
|
32 |
os.makedirs(CLONED_VOICES_DIR, exist_ok=True)
|
33 |
|
34 |
class ClonedVoice(BaseModel):
|
app/voice_enhancement.py
CHANGED
@@ -8,13 +8,15 @@ from typing import Dict, List, Optional, Tuple
|
|
8 |
import logging
|
9 |
from dataclasses import dataclass
|
10 |
from scipy import signal
|
|
|
11 |
|
12 |
# Setup logging
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
# Ensure directories exist
|
20 |
os.makedirs(VOICE_REFERENCES_DIR, exist_ok=True)
|
@@ -476,8 +478,6 @@ def get_voice_segments(voice_name: str, device: torch.device) -> List:
|
|
476 |
Returns:
|
477 |
List of context segments
|
478 |
"""
|
479 |
-
from app.models import Segment
|
480 |
-
|
481 |
if voice_name not in VOICE_PROFILES:
|
482 |
logger.warning(f"Voice {voice_name} not found, defaulting to alloy")
|
483 |
voice_name = "alloy"
|
|
|
8 |
import logging
|
9 |
from dataclasses import dataclass
|
10 |
from scipy import signal
|
11 |
+
from app.models import Segment
|
12 |
|
13 |
# Setup logging
|
14 |
logger = logging.getLogger(__name__)
|
15 |
|
16 |
+
# Constants
|
17 |
+
APP_DIR = os.path.join(os.environ['HOME'], 'app')
|
18 |
+
VOICE_REFERENCES_DIR = os.path.join(APP_DIR, "voice_references")
|
19 |
+
VOICE_PROFILES_DIR = os.path.join(APP_DIR, "voice_profiles")
|
20 |
|
21 |
# Ensure directories exist
|
22 |
os.makedirs(VOICE_REFERENCES_DIR, exist_ok=True)
|
|
|
478 |
Returns:
|
479 |
List of context segments
|
480 |
"""
|
|
|
|
|
481 |
if voice_name not in VOICE_PROFILES:
|
482 |
logger.warning(f"Voice {voice_name} not found, defaulting to alloy")
|
483 |
voice_name = "alloy"
|
app/voice_memory.py
CHANGED
@@ -12,8 +12,9 @@ from app.models import Segment
|
|
12 |
# Setup logging
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
17 |
os.makedirs(VOICE_MEMORIES_DIR, exist_ok=True)
|
18 |
|
19 |
@dataclass
|
|
|
12 |
# Setup logging
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
+
# Constants
|
16 |
+
APP_DIR = os.path.join(os.environ['HOME'], 'app')
|
17 |
+
VOICE_MEMORIES_DIR = os.path.join(APP_DIR, "voice_memories")
|
18 |
os.makedirs(VOICE_MEMORIES_DIR, exist_ok=True)
|
19 |
|
20 |
@dataclass
|