Spaces:
Running
Running
first commit
Browse files- TTS.py +24 -0
- app.py +36 -0
- requirements.txt +7 -0
TTS.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torchaudio
|
3 |
+
from speechbrain.inference.TTS import Tacotron2
|
4 |
+
from speechbrain.inference.vocoders import HIFIGAN
|
5 |
+
from speechbrain.inference.TTS import MSTacotron2
|
6 |
+
#%%
|
7 |
+
|
8 |
+
def TTS(INPUT_TEXT: object,CHOİCE:object) -> object:
|
9 |
+
ms_tacotron2 = MSTacotron2.from_hparams(source="speechbrain/tts-mstacotron2-libritts", savedir="pretrained_models/tts-mstacotron2-libritts")
|
10 |
+
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir="pretrained_models/tts-hifigan-libritts-22050Hz")
|
11 |
+
|
12 |
+
if CHOİCE == "Female":
|
13 |
+
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
|
14 |
+
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
|
15 |
+
mel_output, mel_length, alignment = tacotron2.encode_text(INPUT_TEXT)
|
16 |
+
waveforms = hifi_gan.decode_batch(mel_output)
|
17 |
+
torchaudio.save('Output/base-TTS.wav',waveforms.squeeze(1), 22050)
|
18 |
+
elif CHOİCE == "Male":
|
19 |
+
REFERENCE_SPEECH = "Voice Samples/natural_m.wav"
|
20 |
+
mel_outputs, mel_lengths, alignments = ms_tacotron2.clone_voice(INPUT_TEXT, REFERENCE_SPEECH)
|
21 |
+
waveforms = hifi_gan.decode_batch(mel_outputs)
|
22 |
+
torchaudio.save("Output/base-TTS.wav", waveforms[0], 22050)
|
23 |
+
|
24 |
+
|
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from TTS import TTS
|
3 |
+
import transformers
|
4 |
+
|
5 |
+
def text_to_speech(text, choice):
|
6 |
+
TTS(text, choice)
|
7 |
+
return "Output/base-TTS.wav"
|
8 |
+
|
9 |
+
def convert_to_speech(text, choice):
|
10 |
+
if text:
|
11 |
+
output_file = text_to_speech(text, choice=choice)
|
12 |
+
with open(output_file, 'rb') as audio_file:
|
13 |
+
audio_bytes = audio_file.read()
|
14 |
+
return (audio_bytes, "Conversion successful!")
|
15 |
+
else:
|
16 |
+
return (None, "Please enter some text to convert.")
|
17 |
+
|
18 |
+
def app(text, choice):
|
19 |
+
audio, message = convert_to_speech(text, choice)
|
20 |
+
return audio, message
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=app,
|
24 |
+
inputs=[
|
25 |
+
gr.Textbox(lines=2, placeholder="Enter text here...", label="Text Input"),
|
26 |
+
gr.Radio(choices=["Female", "Male"], label="Speaker")
|
27 |
+
],
|
28 |
+
outputs=[
|
29 |
+
gr.Audio(type="filepath", label="Output Audio"),
|
30 |
+
gr.Textbox(label="Message")
|
31 |
+
],
|
32 |
+
title="Stars AI Text to Speech Conversion App",
|
33 |
+
description="Convert text to speech with a female or male voice."
|
34 |
+
)
|
35 |
+
|
36 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.34.0
|
2 |
+
noisereduce==3.0.2
|
3 |
+
torch
|
4 |
+
torchaudio
|
5 |
+
speechbrain
|
6 |
+
scipy
|
7 |
+
transformers
|