Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
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= []
|