Kragelll commited on
Commit
e2edc99
·
verified ·
1 Parent(s): 9dff5f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from nemo.collections.tts.models import FastPitchModel
4
+ from nemo.collections.tts.models import HifiGanModel
5
+
6
+ # 🔹 Load pretrained models from NeMo
7
+ fastpitch = FastPitchModel.from_pretrained("nvidia/tts_en_fastpitch")
8
+ hifigan = HifiGanModel.from_pretrained("nvidia/tts_hifigan")
9
+
10
+ # 🔹 TTS function
11
+ def tts(text):
12
+ # Convert text → mel spectrogram
13
+ with torch.no_grad():
14
+ spectrogram = fastpitch.parse(text)
15
+ audio = hifigan.convert_spectrogram_to_audio(spectrogram)
16
+ return (22050, audio.cpu().numpy())
17
+
18
+ # 🔹 Gradio UI
19
+ iface = gr.Interface(
20
+ fn=tts,
21
+ inputs=gr.Textbox(label="Enter text"),
22
+ outputs=gr.Audio(label="Generated Speech"),
23
+ title="FastPitch + HiFiGAN (NeMo TTS)",
24
+ description="Enter text and get speech synthesized using NVIDIA NeMo FastPitch and HiFiGAN."
25
+ )
26
+
27
+ iface.launch()