Spaces:
Sleeping
Sleeping
Commit ·
0bb4f0d
1
Parent(s): 2013304
v0
Browse files- app.py +37 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from fastapi import FastAPI, HTTPException
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from TTS.api import TTS
|
| 5 |
+
import uvicorn
|
| 6 |
+
import tempfile
|
| 7 |
+
from fastapi.responses import FileResponse
|
| 8 |
+
|
| 9 |
+
# Charger le modèle TTS
|
| 10 |
+
MODEL_NAME = "tts_models/en/vctk/vits"
|
| 11 |
+
tts = TTS(MODEL_NAME)
|
| 12 |
+
|
| 13 |
+
# Initialiser l'application FastAPI
|
| 14 |
+
app = FastAPI()
|
| 15 |
+
|
| 16 |
+
class TextInput(BaseModel):
|
| 17 |
+
text: str
|
| 18 |
+
|
| 19 |
+
@app.post("/tts")
|
| 20 |
+
def generate_tts(input: TextInput):
|
| 21 |
+
"""Génère un fichier audio à partir du texte donné."""
|
| 22 |
+
if not input.text.strip():
|
| 23 |
+
raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.")
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
| 27 |
+
output_path = tmpfile.name
|
| 28 |
+
|
| 29 |
+
# Générer l'audio
|
| 30 |
+
tts.tts_to_file(text=input.text, file_path=output_path)
|
| 31 |
+
|
| 32 |
+
return FileResponse(output_path, media_type="audio/wav", filename="output.wav")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn
|
| 4 |
+
TTS
|
| 5 |
+
torch
|