myhanhhyugen commited on
Commit
3c1780c
·
verified ·
1 Parent(s): 9e918d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -6,10 +6,10 @@ import numpy as np
6
 
7
 
8
  tts_model = TTSInferencing.from_hparams(source="./",
9
- hparams_file='./hyperparams.yaml',
10
- pymodule_file='./module_classes.py',
11
- # savedir="./",
12
- )
13
 
14
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech")
15
 
@@ -18,18 +18,18 @@ hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech")
18
  # Input text
19
  text = st.text_area("Enter your text here")
20
 
21
- if st.button("To Speech"):
22
- if text:
23
- mel_outputs = tts_model.encode_batch(text)
24
- waveforms = hifi_gan.decode_batch(mel_outputs)
25
-
26
- waveform = waveforms[0].squeeze(1).numpy()
27
-
28
- # Normalize the waveform to the range [-1, 1] if necessary
29
- if np.max(np.abs(waveform)) > 1.0:
30
- waveform /= np.max(np.abs(waveform))
31
-
32
- # Display the audio widget to play the synthesized speech
33
- st.audio(waveform, format="audio/wav", sample_rate = 22050)
34
- else:
35
- st.error("Please enter text to get the speech.")
 
6
 
7
 
8
  tts_model = TTSInferencing.from_hparams(source="./",
9
+ hparams_file='./hyperparams.yaml',
10
+ pymodule_file='./module_classes.py',
11
+ # savedir="./",
12
+ )
13
 
14
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech")
15
 
 
18
  # Input text
19
  text = st.text_area("Enter your text here")
20
 
21
+
22
+ if text:
23
+ mel_outputs = tts_model.encode_batch(text)
24
+ waveforms = hifi_gan.decode_batch(mel_outputs)
25
+
26
+ waveform = waveforms[0].squeeze(1).numpy()
27
+
28
+ # Normalize the waveform to the range [-1, 1] if necessary
29
+ if np.max(np.abs(waveform)) > 1.0:
30
+ waveform /= np.max(np.abs(waveform))
31
+
32
+ # Display the audio widget to play the synthesized speech
33
+ st.audio(waveform, format="audio/wav", sample_rate = 22050)
34
+ else:
35
+ st.error("Please enter text to get the speech.")