amir22010 commited on
Commit
d5c8eb9
·
verified ·
1 Parent(s): c7fc8ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -8,20 +8,23 @@ import wave
8
  #tts
9
  import tempfile
10
  import torchaudio
11
- from speechbrain.inference.TTS import FastSpeech2
 
12
  from speechbrain.inference.vocoders import HIFIGAN
13
 
14
- fastspeech2 = FastSpeech2.from_hparams(source="speechbrain/tts-fastspeech2-ljspeech", savedir="pretrained_models/tts-fastspeech2-ljspeech")
 
15
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
16
 
17
  def text_to_speech(text):
18
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
19
- mel_output, durations, pitch, energy = fastspeech2.encode_text(
20
- [text],
21
- pace=1.0, # scale up/down the speed
22
- pitch_rate=1.0, # scale up/down the pitch
23
- energy_rate=1.0, # scale up/down the energy
24
- )
 
25
  # Running Vocoder (spectrogram-to-waveform)
26
  waveforms = hifi_gan.decode_batch(mel_output)
27
  # Save the waverform
 
8
  #tts
9
  import tempfile
10
  import torchaudio
11
+ #from speechbrain.inference.TTS import FastSpeech2
12
+ from speechbrain.inference.TTS import Tacotron2
13
  from speechbrain.inference.vocoders import HIFIGAN
14
 
15
+ #fastspeech2 = FastSpeech2.from_hparams(source="speechbrain/tts-fastspeech2-ljspeech", savedir="pretrained_models/tts-fastspeech2-ljspeech")
16
+ tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
17
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="pretrained_models/tts-hifigan-ljspeech")
18
 
19
  def text_to_speech(text):
20
  with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
21
+ # mel_output, durations, pitch, energy = fastspeech2.encode_text(
22
+ # [text],
23
+ # pace=1.0, # scale up/down the speed
24
+ # pitch_rate=1.0, # scale up/down the pitch
25
+ # energy_rate=1.0, # scale up/down the energy
26
+ # )
27
+ mel_output, mel_length, alignment = tacotron2.encode_text(text)
28
  # Running Vocoder (spectrogram-to-waveform)
29
  waveforms = hifi_gan.decode_batch(mel_output)
30
  # Save the waverform