Spaces:
Sleeping
Sleeping
AlimOmar commited on
Commit ·
8c1a05f
1
Parent(s): 762c33b
test
Browse files
app.py
CHANGED
|
@@ -20,21 +20,21 @@ from melo.api import TTS
|
|
| 20 |
speed = 1.0
|
| 21 |
device = 'cpu' # or cuda:0
|
| 22 |
|
| 23 |
-
model = TTS(language='EN', device=device)
|
| 24 |
-
speaker_ids = model.hps.data.spk2id
|
| 25 |
-
|
| 26 |
# Pydantic model for request body
|
| 27 |
class TextInput(BaseModel):
|
| 28 |
text: str
|
|
|
|
|
|
|
| 29 |
|
| 30 |
@app.post("/generate-tts")
|
| 31 |
async def generate_tts(input: TextInput):
|
| 32 |
try:
|
|
|
|
|
|
|
| 33 |
# Generate audio to a temporary buffer
|
| 34 |
buffer = io.BytesIO()
|
| 35 |
-
model.tts_to_file(input.text, speaker_ids[
|
| 36 |
buffer.seek(0)
|
| 37 |
-
|
| 38 |
# Return audio as streaming response
|
| 39 |
return StreamingResponse(
|
| 40 |
buffer,
|
|
|
|
| 20 |
speed = 1.0
|
| 21 |
device = 'cpu' # or cuda:0
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
# Pydantic model for request body
|
| 24 |
class TextInput(BaseModel):
|
| 25 |
text: str
|
| 26 |
+
lang: str
|
| 27 |
+
speaker: str
|
| 28 |
|
| 29 |
@app.post("/generate-tts")
|
| 30 |
async def generate_tts(input: TextInput):
|
| 31 |
try:
|
| 32 |
+
model = TTS(language=input.lang, device=device)
|
| 33 |
+
speaker_ids = model.hps.data.spk2id
|
| 34 |
# Generate audio to a temporary buffer
|
| 35 |
buffer = io.BytesIO()
|
| 36 |
+
model.tts_to_file(input.text, speaker_ids[input.speaker], buffer, speed=speed, format='wav')
|
| 37 |
buffer.seek(0)
|
|
|
|
| 38 |
# Return audio as streaming response
|
| 39 |
return StreamingResponse(
|
| 40 |
buffer,
|