Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import librosa
|
4 |
+
import numpy as np
|
5 |
+
from scipy.io.wavfile import write
|
6 |
+
|
7 |
+
def narrate_text(text):
|
8 |
+
narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
|
9 |
+
narrated_text = narrator(text)
|
10 |
+
audio_data = narrated_text["audio"][0]
|
11 |
+
sampling_rate = narrated_text["sampling_rate"]
|
12 |
+
audio_data = librosa.resample(audio_data, orig_sr=sampling_rate, target_sr=22050)
|
13 |
+
audio_data = (audio_data * 32767).astype(np.int16)
|
14 |
+
with open("output.wav", "wb") as f:
|
15 |
+
write(f, 22050, audio_data)
|
16 |
+
return "output.wav"
|
17 |
+
|
18 |
+
gr.Interface(
|
19 |
+
fn=narrate_text,
|
20 |
+
inputs=gr.Textbox(label="Enter Text Here",
|
21 |
+
lines=7),
|
22 |
+
outputs="audio",
|
23 |
+
title="Speak Out Loud - Text to Speech Assistant",
|
24 |
+
description="Upload the text that you want to hear out loud!!!",
|
25 |
+
article =
|
26 |
+
'''<div>
|
27 |
+
<p style="text-align: center"> All you need to do is to upload your text and hit submit, then wait for compiling. After that click on Play/Pause for listing to the audio. The audio is saved in a wav format.</p>
|
28 |
+
</div>''',
|
29 |
+
).launch()
|