Skip to content

Commit 76e6b44

Browse files
committed
fix: Resolve frontend path issues and TTS audio file paths
1 parent 31c7c48 commit 76e6b44

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

backend/main.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import List, Optional, Dict, Any
77
import uvicorn
88
import os
9+
import sys
910
from pathlib import Path
1011

1112
# Import our modules
@@ -54,20 +55,10 @@
5455
except ImportError:
5556
from paths import get_paths
5657

57-
# Mount static files for audio cache and frontend
58+
# Mount static files for audio cache
5859
paths = get_paths()
5960
app.mount("/audio_cache", StaticFiles(directory=str(paths.audio_cache)), name="audio_cache")
6061

61-
# Mount frontend static files
62-
frontend_path = paths.base_path / "frontend" / "dist"
63-
if frontend_path.exists():
64-
app.mount("/", StaticFiles(directory=str(frontend_path), html=True), name="frontend")
65-
else:
66-
# Fallback for development when running from source
67-
dev_frontend_path = Path(__file__).parent.parent / "frontend" / "dist"
68-
if dev_frontend_path.exists():
69-
app.mount("/", StaticFiles(directory=str(dev_frontend_path), html=True), name="frontend")
70-
7162
# API info endpoint (moved from root to avoid conflict with frontend)
7263
@app.get("/api/info")
7364
async def api_info():
@@ -288,6 +279,25 @@ async def get_available_voices(omni_model: str):
288279
except Exception as e:
289280
raise HTTPException(status_code=500, detail=f"Error getting voices: {str(e)}")
290281

282+
# Mount frontend static files (moved after API endpoints to avoid conflicts)
283+
if getattr(sys, 'frozen', False):
284+
# Running as PyInstaller bundle - frontend files are in the bundled directory
285+
bundled_frontend_path = Path(sys._MEIPASS) / "frontend" / "dist"
286+
if bundled_frontend_path.exists():
287+
app.mount("/", StaticFiles(directory=str(bundled_frontend_path), html=True), name="frontend")
288+
else:
289+
print(f"Warning: Frontend directory not found at {bundled_frontend_path}")
290+
else:
291+
# Development environment
292+
frontend_path = paths.base_path / "frontend" / "dist"
293+
if frontend_path.exists():
294+
app.mount("/", StaticFiles(directory=str(frontend_path), html=True), name="frontend")
295+
else:
296+
# Fallback for development when running from source
297+
dev_frontend_path = Path(__file__).parent.parent / "frontend" / "dist"
298+
if dev_frontend_path.exists():
299+
app.mount("/", StaticFiles(directory=str(dev_frontend_path), html=True), name="frontend")
300+
291301
# Error handler
292302
@app.exception_handler(Exception)
293303
async def general_exception_handler(request, exc):

backend/omni_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ async def text_to_speech(self, request: TTSInput) -> TTSResult:
207207
# Check cache first
208208
cache_path = self._get_tts_cache_path(request.text, request.voice)
209209
if cache_path.exists():
210+
# Return web-accessible path relative to /audio_cache mount point
211+
web_path = f"/audio_cache/tts/{cache_path.name}"
210212
return TTSResult(
211213
text=request.text,
212-
audio_file_path=str(cache_path)
214+
audio_file_path=web_path
213215
)
214216

215217
# Prepare TTS prompt
@@ -229,9 +231,11 @@ async def text_to_speech(self, request: TTSInput) -> TTSResult:
229231
audio_np = np.frombuffer(mp3_bytes, dtype=np.int16)
230232
sf.write(cache_path, audio_np, samplerate=24000)
231233

234+
# Return web-accessible path relative to /audio_cache mount point
235+
web_path = f"/audio_cache/tts/{cache_path.name}"
232236
return TTSResult(
233237
text=request.text,
234-
audio_file_path=str(cache_path)
238+
audio_file_path=web_path
235239
)
236240
else:
237241
raise Exception("No audio response received from TTS request")

0 commit comments

Comments
 (0)