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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -4,9 +4,9 @@ import os
4
  from groq import Groq
5
  import numpy as np
6
  import wave
 
7
 
8
  #tts
9
- import tempfile
10
  import torchaudio
11
  #from speechbrain.inference.TTS import FastSpeech2
12
  from speechbrain.inference.TTS import Tacotron2
@@ -17,19 +17,13 @@ tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech",
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
31
- torchaudio.save(temp_file.name, waveforms.squeeze(1), 22050)
32
- return temp_file.name
33
 
34
  def combine_audio_files(audio_files):
35
  data= []
 
4
  from groq import Groq
5
  import numpy as np
6
  import wave
7
+ import uuid
8
 
9
  #tts
 
10
  import torchaudio
11
  #from speechbrain.inference.TTS import FastSpeech2
12
  from speechbrain.inference.TTS import Tacotron2
 
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
+ mel_output, mel_length, alignment = tacotron2.encode_text(text)
21
+ # Running Vocoder (spectrogram-to-waveform)
22
+ waveforms = hifi_gan.decode_batch(mel_output)
23
+ # Save the waverform
24
+ outfile = f"{uuid.uuid4()}.wav"
25
+ torchaudio.save(outfile, waveforms.squeeze(1), 22050)
26
+ return outfile
 
 
 
 
 
 
27
 
28
  def combine_audio_files(audio_files):
29
  data= []