neuralleap commited on
Commit
5eeb234
1 Parent(s): 36cc7a1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -2
main.py CHANGED
@@ -4,6 +4,16 @@ from fastapi.responses import FileResponse, HTMLResponse
4
  import os
5
  import io
6
 
 
 
 
 
 
 
 
 
 
 
7
  from gradio_client import Client
8
 
9
  client = Client("physician-ai/speech-to-text")
@@ -48,12 +58,12 @@ xtts.to("cuda")
48
  @app.get("/text-to-speech/")
49
  def text_to_speech(text,language):
50
  global xtts
51
- audio_file = 'text_to_speech.mp3'
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="en",file_path=audio_file)
58
  return FileResponse(audio_file, media_type='audio/mpeg')
59
 
 
4
  import os
5
  import io
6
 
7
+ import httpcore
8
+ setattr(httpcore, 'SyncHTTPTransport', 'AsyncHTTPProxy')
9
+
10
+ import googletrans
11
+ from googletrans import Translator
12
+ translator = Translator()
13
+ lan = googletrans.LANGUAGES
14
+ keys = list(lan.keys())
15
+ vals = list(lan.values())
16
+
17
  from gradio_client import Client
18
 
19
  client = Client("physician-ai/speech-to-text")
 
58
  @app.get("/text-to-speech/")
59
  def text_to_speech(text,language):
60
  global xtts
61
+ audio_file = 'text_to_speech.wav'
62
  if language=="vietnamese":
63
  from gtts import gTTS
64
  tts = gTTS(text)
65
  tts.save(audio_file)
66
  else:
67
+ xtts.tts_to_file(text,speaker_wav="input.wav",language=keys[vals.index(language)],file_path=audio_file)
68
  return FileResponse(audio_file, media_type='audio/mpeg')
69