Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
from fastapi import FastAPI, Response
|
| 2 |
-
from fastapi.staticfiles import StaticFiles
|
| 3 |
from fastapi.responses import HTMLResponse
|
| 4 |
import edge_tts
|
| 5 |
import asyncio
|
|
@@ -9,12 +8,8 @@ import os
|
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
-
# Servir arquivos estáticos
|
| 13 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 14 |
-
|
| 15 |
-
# HTML como string (vou mostrar o conteúdo abaixo)
|
| 16 |
HTML_CONTENT = """
|
| 17 |
-
|
| 18 |
<html lang="pt-BR">
|
| 19 |
<head>
|
| 20 |
<meta charset="UTF-8">
|
|
@@ -188,7 +183,6 @@ HTML_CONTENT = """
|
|
| 188 |
|
| 189 |
const voice = document.querySelector('input[name="voice"]:checked').value;
|
| 190 |
|
| 191 |
-
// Mostrar loading e desabilitar botão
|
| 192 |
loading.style.display = 'block';
|
| 193 |
convertBtn.disabled = true;
|
| 194 |
audioOutput.style.display = 'none';
|
|
@@ -233,18 +227,14 @@ async def synthesize_speech(request_data: dict):
|
|
| 233 |
text = request_data.get("text", "")
|
| 234 |
voice = request_data.get("voice", "pt-BR-FranciscaNeural")
|
| 235 |
|
| 236 |
-
# Gerar nome único para o arquivo
|
| 237 |
output_file = f"temp_{hash(text + voice)}.mp3"
|
| 238 |
|
| 239 |
-
# Criar comunicação com edge-tts
|
| 240 |
communicate = edge_tts.Communicate(text, voice)
|
| 241 |
await communicate.save(output_file)
|
| 242 |
|
| 243 |
-
# Ler o arquivo
|
| 244 |
with open(output_file, "rb") as f:
|
| 245 |
audio_data = f.read()
|
| 246 |
|
| 247 |
-
# Limpar o arquivo temporário
|
| 248 |
os.remove(output_file)
|
| 249 |
|
| 250 |
return Response(content=audio_data, media_type="audio/mpeg")
|
|
@@ -252,5 +242,4 @@ async def synthesize_speech(request_data: dict):
|
|
| 252 |
return Response(content=str(e), status_code=500)
|
| 253 |
|
| 254 |
if __name__ == "__main__":
|
| 255 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 256 |
-
|
|
|
|
| 1 |
from fastapi import FastAPI, Response
|
|
|
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
import edge_tts
|
| 4 |
import asyncio
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
HTML_CONTENT = """
|
| 12 |
+
<!DOCTYPE html>
|
| 13 |
<html lang="pt-BR">
|
| 14 |
<head>
|
| 15 |
<meta charset="UTF-8">
|
|
|
|
| 183 |
|
| 184 |
const voice = document.querySelector('input[name="voice"]:checked').value;
|
| 185 |
|
|
|
|
| 186 |
loading.style.display = 'block';
|
| 187 |
convertBtn.disabled = true;
|
| 188 |
audioOutput.style.display = 'none';
|
|
|
|
| 227 |
text = request_data.get("text", "")
|
| 228 |
voice = request_data.get("voice", "pt-BR-FranciscaNeural")
|
| 229 |
|
|
|
|
| 230 |
output_file = f"temp_{hash(text + voice)}.mp3"
|
| 231 |
|
|
|
|
| 232 |
communicate = edge_tts.Communicate(text, voice)
|
| 233 |
await communicate.save(output_file)
|
| 234 |
|
|
|
|
| 235 |
with open(output_file, "rb") as f:
|
| 236 |
audio_data = f.read()
|
| 237 |
|
|
|
|
| 238 |
os.remove(output_file)
|
| 239 |
|
| 240 |
return Response(content=audio_data, media_type="audio/mpeg")
|
|
|
|
| 242 |
return Response(content=str(e), status_code=500)
|
| 243 |
|
| 244 |
if __name__ == "__main__":
|
| 245 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|