mrfakename commited on
Commit
406e977
β€’
1 Parent(s): 7a62809

Remove tempfile dependency

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. melo/api.py +2 -2
app.py CHANGED
@@ -8,9 +8,9 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
8
  model = TTS(language='EN', device=device)
9
  speaker_ids = model.hps.data.spk2id
10
  def synthesize(speaker, text, speed=1.0, progress=gr.Progress()):
11
- with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
12
- model.tts_to_file(text, speaker_ids[speaker], f.name, speed=speed, pbar=progress.tqdm)
13
- return f.name
14
  with gr.Blocks() as demo:
15
  gr.Markdown('# MeloTTS\n\nAn unofficial demo of [MeloTTS](https://github.com/myshell-ai/MeloTTS) from MyShell AI. MeloTTS is a permissively licensed (MIT) SOTA multi-speaker TTS model.\n\nI am not affiliated with MyShell AI in any way.\n\nThis demo currently only supports English, but the model itself supports other languages.')
16
  with gr.Group():
 
8
  model = TTS(language='EN', device=device)
9
  speaker_ids = model.hps.data.spk2id
10
  def synthesize(speaker, text, speed=1.0, progress=gr.Progress()):
11
+ bio = io.BytesIO()
12
+ model.tts_to_file(text, speaker_ids[speaker], bio, speed=speed, pbar=progress.tqdm, format='wav')
13
+ return bio.getvalue()
14
  with gr.Blocks() as demo:
15
  gr.Markdown('# MeloTTS\n\nAn unofficial demo of [MeloTTS](https://github.com/myshell-ai/MeloTTS) from MyShell AI. MeloTTS is a permissively licensed (MIT) SOTA multi-speaker TTS model.\n\nI am not affiliated with MyShell AI in any way.\n\nThis demo currently only supports English, but the model itself supports other languages.')
16
  with gr.Group():
melo/api.py CHANGED
@@ -70,7 +70,7 @@ class TTS(nn.Module):
70
  # print(" > ===========================")
71
  return texts
72
 
73
- def tts_to_file(self, text, speaker_id, output_path=None, sdp_ratio=0.2, noise_scale=0.6, noise_scale_w=0.8, speed=1.0, pbar=None):
74
  language = self.language
75
  texts = self.split_sentences_into_pieces(text, language)
76
  audio_list = []
@@ -113,4 +113,4 @@ class TTS(nn.Module):
113
  if output_path is None:
114
  return audio
115
  else:
116
- soundfile.write(output_path, audio, self.hps.data.sampling_rate)
 
70
  # print(" > ===========================")
71
  return texts
72
 
73
+ def tts_to_file(self, text, speaker_id, output_path=None, sdp_ratio=0.2, noise_scale=0.6, noise_scale_w=0.8, speed=1.0, pbar=None, format=None):
74
  language = self.language
75
  texts = self.split_sentences_into_pieces(text, language)
76
  audio_list = []
 
113
  if output_path is None:
114
  return audio
115
  else:
116
+ soundfile.write(output_path, audio, self.hps.data.sampling_rate, format)