Spaces:
Running
Running
Update admin_routes.py
Browse files- admin_routes.py +65 -0
admin_routes.py
CHANGED
@@ -1535,6 +1535,71 @@ async def export_project(
|
|
1535 |
log(f"β
Project '{project['name']}' exported by {username}")
|
1536 |
return export_data
|
1537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1538 |
# ===================== Activity Log Endpoints =====================
|
1539 |
@router.get("/activity-log")
|
1540 |
async def get_activity_log(
|
|
|
1535 |
log(f"β
Project '{project['name']}' exported by {username}")
|
1536 |
return export_data
|
1537 |
|
1538 |
+
# ===================== TTS Endpoints =====================
|
1539 |
+
class TTSRequest(BaseModel):
|
1540 |
+
text: str
|
1541 |
+
voice_id: Optional[str] = None
|
1542 |
+
model_id: Optional[str] = None
|
1543 |
+
output_format: Optional[str] = "mp3_44100_128"
|
1544 |
+
|
1545 |
+
@router.post("/tts/generate")
|
1546 |
+
async def generate_tts(
|
1547 |
+
request: TTSRequest,
|
1548 |
+
username: str = Depends(verify_token)
|
1549 |
+
):
|
1550 |
+
"""Generate TTS audio from text"""
|
1551 |
+
try:
|
1552 |
+
config = load_config()
|
1553 |
+
env_config = config.get("config", {})
|
1554 |
+
|
1555 |
+
tts_engine = env_config.get("tts_engine", "no_tts")
|
1556 |
+
if tts_engine == "no_tts":
|
1557 |
+
raise HTTPException(status_code=400, detail="TTS is not configured")
|
1558 |
+
|
1559 |
+
# Get TTS provider
|
1560 |
+
from config_provider import ConfigProvider
|
1561 |
+
cfg = ConfigProvider.get()
|
1562 |
+
api_key = cfg.global_config.get_tts_api_key()
|
1563 |
+
|
1564 |
+
if not api_key:
|
1565 |
+
raise HTTPException(status_code=400, detail="TTS API key not configured")
|
1566 |
+
|
1567 |
+
# Import here to avoid circular dependency
|
1568 |
+
from tts_interface import create_tts_provider
|
1569 |
+
|
1570 |
+
tts_provider = create_tts_provider(tts_engine, api_key)
|
1571 |
+
if not tts_provider:
|
1572 |
+
raise HTTPException(status_code=500, detail="Failed to create TTS provider")
|
1573 |
+
|
1574 |
+
log(f"π€ Generating TTS for {len(request.text)} characters using {tts_engine}")
|
1575 |
+
|
1576 |
+
# Generate audio
|
1577 |
+
audio_data = await tts_provider.synthesize(
|
1578 |
+
text=request.text,
|
1579 |
+
voice_id=request.voice_id,
|
1580 |
+
model_id=request.model_id,
|
1581 |
+
output_format=request.output_format
|
1582 |
+
)
|
1583 |
+
|
1584 |
+
# Return audio data
|
1585 |
+
from fastapi.responses import Response
|
1586 |
+
|
1587 |
+
content_type = "audio/mpeg" if request.output_format.startswith("mp3") else "audio/wav"
|
1588 |
+
|
1589 |
+
return Response(
|
1590 |
+
content=audio_data,
|
1591 |
+
media_type=content_type,
|
1592 |
+
headers={
|
1593 |
+
"Content-Disposition": f"attachment; filename=tts_output.{request.output_format.split('_')[0]}"
|
1594 |
+
}
|
1595 |
+
)
|
1596 |
+
|
1597 |
+
except HTTPException:
|
1598 |
+
raise
|
1599 |
+
except Exception as e:
|
1600 |
+
log(f"β TTS generation error: {e}")
|
1601 |
+
raise HTTPException(status_code=500, detail=str(e))
|
1602 |
+
|
1603 |
# ===================== Activity Log Endpoints =====================
|
1604 |
@router.get("/activity-log")
|
1605 |
async def get_activity_log(
|