Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,22 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
# Install transformers if not installed
|
4 |
-
# !pip install transformers gradio
|
5 |
-
|
6 |
-
from transformers import pipeline
|
7 |
import gradio as gr
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
os.system('pip install transformers gradio')
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Load a pre-trained TTS pipeline
|
16 |
-
tts_pipeline = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
|
17 |
|
18 |
-
#
|
19 |
-
def
|
20 |
-
audio =
|
21 |
-
return audio[
|
22 |
|
23 |
-
#
|
24 |
-
iface = gr.Interface(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
description="Type your text and generate the corresponding audio."
|
30 |
-
)
|
31 |
|
32 |
-
#
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
+
# Hugging Face TTS λͺ¨λΈ λ‘λ (λΆκ°λ¦¬μμ΄ λͺ¨λΈλ‘ λ³κ²½ νμ)
|
6 |
+
tts = pipeline(task="text-to-speech", model="facebook/mms-tts-bul", device=0 if torch.cuda.is_available() else -1)
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# TTS λ³ν ν¨μ
|
9 |
+
def tts_generate(text):
|
10 |
+
audio = tts(text, return_tensors=True)
|
11 |
+
return (audio['speech'].numpy(), 22050) # λ°νν μνλ§ μλμ μ€λμ€ λ°μ΄ν°
|
12 |
|
13 |
+
# Gradio μΈν°νμ΄μ€ μμ±
|
14 |
+
iface = gr.Interface(fn=tts_generate,
|
15 |
+
inputs="text",
|
16 |
+
outputs="audio",
|
17 |
+
title="Bulgarian TTS Generator",
|
18 |
+
description="Enter text to generate speech in Bulgarian.")
|
|
|
|
|
19 |
|
20 |
+
# μΈν°νμ΄μ€ μ€ν
|
21 |
+
if __name__ == "__main__":
|
22 |
+
iface.launch()
|