File size: 1,156 Bytes
fa0ce57
 
2c8df7d
 
e816c9c
fa0ce57
 
 
3c1780c
 
 
 
fa0ce57
2c8df7d
fa0ce57
 
 
 
9e918d6
 
3c1780c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from TTSInferencing import TTSInferencing
from speechbrain.inference.vocoders import HIFIGAN
# import torchaudio
import  streamlit as st
import numpy as np


tts_model = TTSInferencing.from_hparams(source="./",
                                    hparams_file='./hyperparams.yaml',
                                    pymodule_file='./module_classes.py',
                                    # savedir="./",
                                    )

hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech")

# text = ["Hello I am a girl", "How is your day going", "I hope you are doing well"]

# Input text
text = st.text_area("Enter your text here")


if text:
    mel_outputs = tts_model.encode_batch(text)
    waveforms = hifi_gan.decode_batch(mel_outputs)

    waveform =  waveforms[0].squeeze(1).numpy()

    # Normalize the waveform to the range [-1, 1] if necessary
    if np.max(np.abs(waveform)) > 1.0:
        waveform /= np.max(np.abs(waveform))

    # Display the audio widget to play the synthesized speech
    st.audio(waveform, format="audio/wav", sample_rate = 22050)
else:
    st.error("Please enter text to get the speech.")