Commit ·
c8d1d7c
1
Parent(s): 133828c
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from fastapi.responses import StreamingResponse
|
|
|
|
| 3 |
import os
|
| 4 |
import io
|
| 5 |
|
|
@@ -33,4 +34,21 @@ async def speech_to_text(file: UploadFile = File(...)):
|
|
| 33 |
return respond
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile
|
| 2 |
from fastapi.responses import StreamingResponse
|
| 3 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 4 |
import os
|
| 5 |
import io
|
| 6 |
|
|
|
|
| 34 |
return respond
|
| 35 |
|
| 36 |
|
| 37 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 38 |
+
from TTS.api import TTS
|
| 39 |
+
|
| 40 |
+
model_names = TTS().list_models()
|
| 41 |
+
m = model_names[0]
|
| 42 |
+
print(model_names)
|
| 43 |
+
tts = TTS(m, gpu=True)
|
| 44 |
+
#tts.to("cpu") # no GPU or Amd
|
| 45 |
+
tts.to("cuda")
|
| 46 |
+
|
| 47 |
+
@app.get("/text-to-speech/")
|
| 48 |
+
def text_to_speech(text: str):
|
| 49 |
+
from gtts import gTTS
|
| 50 |
+
tts = gTTS(text)
|
| 51 |
+
audio_file = 'text_to_speech.mp3'
|
| 52 |
+
tts.save(audio_file)
|
| 53 |
+
return FileResponse(audio_file, media_type='audio/mpeg')
|
| 54 |
|