neuralleap commited on
Commit
fcbb581
·
verified ·
1 Parent(s): eaa0985

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -15
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
- #from TTS.api import TTS
40
 
41
- #model_names = TTS().list_models()
42
- #m = model_names[0]
43
- #print(model_names)
44
- #global xtts
45
- #xtts = TTS(m, gpu=True)
46
  #tts.to("cpu") # no GPU or Amd
47
- #xtts.to("cuda")
48
 
49
  @app.get("/text-to-speech/")
50
  def text_to_speech(text,language):
51
- #global xtts
52
  audio_file = 'text_to_speech.wav'
53
- #if language=="vietnamese":
54
- from gtts import gTTS
55
- tts = gTTS(text)
56
- tts.save(audio_file)
57
- #else:
58
- #xtts.tts_to_file(text,speaker_wav="input.wav",language=keys[vals.index(language)],file_path=audio_file)
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