Update main.py
Browse files
main.py
CHANGED
|
@@ -34,28 +34,27 @@ async def translate(text,language):
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
-
#text_to_speech bock
|
| 38 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
#xtts = TTS(m, gpu=True)
|
| 46 |
#tts.to("cpu") # no GPU or Amd
|
| 47 |
-
|
| 48 |
|
| 49 |
@app.get("/text-to-speech/")
|
| 50 |
def text_to_speech(text,language):
|
| 51 |
-
|
| 52 |
audio_file = 'text_to_speech.wav'
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
return FileResponse(audio_file, media_type='audio/mpeg')
|
| 60 |
|
| 61 |
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
+
#text_to_speech bock===========================================================================
|
| 38 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 39 |
+
from TTS.api import TTS
|
| 40 |
|
| 41 |
+
model_names = TTS().list_models()
|
| 42 |
+
m = model_names[0]
|
| 43 |
+
global xtts
|
| 44 |
+
xtts = TTS(m, gpu=True)
|
|
|
|
| 45 |
#tts.to("cpu") # no GPU or Amd
|
| 46 |
+
xtts.to("cuda")
|
| 47 |
|
| 48 |
@app.get("/text-to-speech/")
|
| 49 |
def text_to_speech(text,language):
|
| 50 |
+
global xtts
|
| 51 |
audio_file = 'text_to_speech.wav'
|
| 52 |
+
if language=="vietnamese":
|
| 53 |
+
from gtts import gTTS
|
| 54 |
+
tts = gTTS(text)
|
| 55 |
+
tts.save(audio_file)
|
| 56 |
+
else:
|
| 57 |
+
xtts.tts_to_file(text,speaker_wav="input.wav",language=keys[vals.index(language)],file_path=audio_file)
|
| 58 |
return FileResponse(audio_file, media_type='audio/mpeg')
|
| 59 |
|
| 60 |
|