Spaces:
Sleeping
Sleeping
Commit ·
af681c6
1
Parent(s): eb91d30
new params
Browse files
app.py
CHANGED
|
@@ -26,8 +26,19 @@ try:
|
|
| 26 |
except Exception as e:
|
| 27 |
print("Erreur lors du test du modèle :", e)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
class TextInput(BaseModel):
|
| 30 |
text: str
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
@app.post("/tts")
|
| 33 |
def generate_tts(input: TextInput):
|
|
@@ -35,8 +46,15 @@ def generate_tts(input: TextInput):
|
|
| 35 |
if not input.text.strip():
|
| 36 |
raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
-
print("
|
|
|
|
| 40 |
|
| 41 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
| 42 |
output_path = tmpfile.name
|
|
@@ -45,8 +63,15 @@ def generate_tts(input: TextInput):
|
|
| 45 |
|
| 46 |
|
| 47 |
# Générer l'audio
|
| 48 |
-
tts.tts_to_file(
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
print("tmp file generated")
|
| 51 |
|
| 52 |
return FileResponse(output_path, media_type="audio/wav", filename="output.wav")
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
print("Erreur lors du test du modèle :", e)
|
| 28 |
|
| 29 |
+
|
| 30 |
+
SPEAKER_MAPPING = {
|
| 31 |
+
"Eden": "p339",
|
| 32 |
+
"voice2": "p340",
|
| 33 |
+
# Ajoutez d'autres correspondances si nécessaire
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
class TextInput(BaseModel):
|
| 38 |
text: str
|
| 39 |
+
emotion: str = "neutral"
|
| 40 |
+
speaker: str = "Eden"
|
| 41 |
+
|
| 42 |
|
| 43 |
@app.post("/tts")
|
| 44 |
def generate_tts(input: TextInput):
|
|
|
|
| 46 |
if not input.text.strip():
|
| 47 |
raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.")
|
| 48 |
|
| 49 |
+
speaker_code = SPEAKER_MAPPING.get(input.speaker)
|
| 50 |
+
if speaker_code is None:
|
| 51 |
+
raise HTTPException(
|
| 52 |
+
status_code=400, detail=f"Le speaker '{input.speaker}' n'est pas reconnu.")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
try:
|
| 56 |
+
print("Generation starts:", input.text.strip(), "avec emotion:",
|
| 57 |
+
input.emotion, "et speaker:", input.speaker)
|
| 58 |
|
| 59 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
| 60 |
output_path = tmpfile.name
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# Générer l'audio
|
| 66 |
+
tts.tts_to_file(
|
| 67 |
+
text=input.text,
|
| 68 |
+
speaker=speaker_code,
|
| 69 |
+
speaker_wav=None,
|
| 70 |
+
age=22,
|
| 71 |
+
gender="F",
|
| 72 |
+
emotion=input.emotion,
|
| 73 |
+
file_path=output_path
|
| 74 |
+
)
|
| 75 |
print("tmp file generated")
|
| 76 |
|
| 77 |
return FileResponse(output_path, media_type="audio/wav", filename="output.wav")
|