Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,41 +14,6 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
| 14 |
|
| 15 |
# HTML como string (vou mostrar o conteúdo abaixo)
|
| 16 |
HTML_CONTENT = """
|
| 17 |
-
<!DOCTYPE html>
|
| 18 |
-
... # (conteúdo HTML que mostrarei em seguida)
|
| 19 |
-
"""
|
| 20 |
-
|
| 21 |
-
@app.get("/", response_class=HTMLResponse)
|
| 22 |
-
async def read_root():
|
| 23 |
-
return HTML_CONTENT
|
| 24 |
-
|
| 25 |
-
@app.post("/synthesize")
|
| 26 |
-
async def synthesize_speech(request_data: dict):
|
| 27 |
-
try:
|
| 28 |
-
text = request_data.get("text", "")
|
| 29 |
-
voice = request_data.get("voice", "pt-BR-FranciscaNeural")
|
| 30 |
-
|
| 31 |
-
# Gerar nome único para o arquivo
|
| 32 |
-
output_file = f"temp_{hash(text + voice)}.mp3"
|
| 33 |
-
|
| 34 |
-
# Criar comunicação com edge-tts
|
| 35 |
-
communicate = edge_tts.Communicate(text, voice)
|
| 36 |
-
await communicate.save(output_file)
|
| 37 |
-
|
| 38 |
-
# Ler o arquivo
|
| 39 |
-
with open(output_file, "rb") as f:
|
| 40 |
-
audio_data = f.read()
|
| 41 |
-
|
| 42 |
-
# Limpar o arquivo temporário
|
| 43 |
-
os.remove(output_file)
|
| 44 |
-
|
| 45 |
-
return Response(content=audio_data, media_type="audio/mpeg")
|
| 46 |
-
except Exception as e:
|
| 47 |
-
return Response(content=str(e), status_code=500)
|
| 48 |
-
|
| 49 |
-
if __name__ == "__main__":
|
| 50 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 51 |
-
|
| 52 |
<!DOCTYPE html>
|
| 53 |
<html lang="pt-BR">
|
| 54 |
<head>
|
|
@@ -255,4 +220,37 @@ if __name__ == "__main__":
|
|
| 255 |
});
|
| 256 |
</script>
|
| 257 |
</body>
|
| 258 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# HTML como string (vou mostrar o conteúdo abaixo)
|
| 16 |
HTML_CONTENT = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
<!DOCTYPE html>
|
| 18 |
<html lang="pt-BR">
|
| 19 |
<head>
|
|
|
|
| 220 |
});
|
| 221 |
</script>
|
| 222 |
</body>
|
| 223 |
+
</html>
|
| 224 |
+
"""
|
| 225 |
+
|
| 226 |
+
@app.get("/", response_class=HTMLResponse)
|
| 227 |
+
async def read_root():
|
| 228 |
+
return HTML_CONTENT
|
| 229 |
+
|
| 230 |
+
@app.post("/synthesize")
|
| 231 |
+
async def synthesize_speech(request_data: dict):
|
| 232 |
+
try:
|
| 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")
|
| 251 |
+
except Exception as e:
|
| 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 |
+
|