jayesh95 commited on
Commit
9e8179c
1 Parent(s): b95859f

reformatted and removed comments

Browse files
Files changed (1) hide show
  1. app.py +26 -29
app.py CHANGED
@@ -38,7 +38,6 @@ print(model.device)
38
 
39
  # Whisper - speech-to-text
40
  def whisper_stt(audio):
41
- print("Inside Whisper TTS")
42
  # load audio and pad/trim it to fit 30 seconds
43
  audio = whisper.load_audio(audio)
44
  audio = whisper.pad_or_trim(audio)
@@ -65,32 +64,32 @@ def whisper_stt(audio):
65
 
66
  # Coqui - Text-to-Speech
67
  def tts(text: str, model_name: str):
68
- if len(text) > MAX_TXT_LEN:
69
- text = text[:MAX_TXT_LEN]
70
- print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
71
- print(text, model_name)
72
- # download model
73
- model_path, config_path, model_item = tts_manager.download_model(f"tts_models/{model_name}")
74
- vocoder_name: Optional[str] = model_item["default_vocoder"]
75
- # download vocoder
76
- vocoder_path = None
77
- vocoder_config_path = None
78
- if vocoder_name is not None:
79
- vocoder_path, vocoder_config_path, _ = tts_manager.download_model(vocoder_name)
80
- # init synthesizer
81
- synthesizer = Synthesizer(
82
- model_path, config_path, None, None, vocoder_path, vocoder_config_path,
83
- )
84
-
85
- # synthesize
86
- if synthesizer is None:
87
- raise NameError("model not found")
88
- wavs = synthesizer.tts(text)
89
-
90
- # return output
91
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
92
- synthesizer.save_wav(wavs, fp)
93
- return fp.name
94
 
95
  def engine(audio, context):
96
  # Get voice query to text
@@ -140,7 +139,5 @@ with demo:
140
 
141
  b1.click(engine, inputs=[in_audio, in_context], outputs=[out_query, out_textbox, out_audio])
142
 
143
- #with gr.Row():
144
- # gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=ysharma_Voice-to-Youtube)")
145
 
146
  demo.launch(enable_queue=True, debug=True)
 
38
 
39
  # Whisper - speech-to-text
40
  def whisper_stt(audio):
 
41
  # load audio and pad/trim it to fit 30 seconds
42
  audio = whisper.load_audio(audio)
43
  audio = whisper.pad_or_trim(audio)
 
64
 
65
  # Coqui - Text-to-Speech
66
  def tts(text: str, model_name: str):
67
+ if len(text) > MAX_TXT_LEN:
68
+ text = text[:MAX_TXT_LEN]
69
+ print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
70
+ print(text, model_name)
71
+ # download model
72
+ model_path, config_path, model_item = tts_manager.download_model(f"tts_models/{model_name}")
73
+ vocoder_name: Optional[str] = model_item["default_vocoder"]
74
+ # download vocoder
75
+ vocoder_path = None
76
+ vocoder_config_path = None
77
+ if vocoder_name is not None:
78
+ vocoder_path, vocoder_config_path, _ = tts_manager.download_model(vocoder_name)
79
+ # init synthesizer
80
+ synthesizer = Synthesizer(
81
+ model_path, config_path, None, None, vocoder_path, vocoder_config_path,
82
+ )
83
+
84
+ # synthesize
85
+ if synthesizer is None:
86
+ raise NameError("model not found")
87
+ wavs = synthesizer.tts(text)
88
+
89
+ # return output
90
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
91
+ synthesizer.save_wav(wavs, fp)
92
+ return fp.name
93
 
94
  def engine(audio, context):
95
  # Get voice query to text
 
139
 
140
  b1.click(engine, inputs=[in_audio, in_context], outputs=[out_query, out_textbox, out_audio])
141
 
 
 
142
 
143
  demo.launch(enable_queue=True, debug=True)