Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.utils import logging
|
2 |
+
|
3 |
+
logging.set_verbosity_error()
|
4 |
+
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
import soundfile as sf
|
8 |
+
import numpy as np
|
9 |
+
import tempfile
|
10 |
+
|
11 |
+
def launch(input_text):
|
12 |
+
try:
|
13 |
+
# Assuming `narrator` function returns a numpy array with audio data and a sampling rate.
|
14 |
+
narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
|
15 |
+
out = narrator(input_text)
|
16 |
+
audio_data, samplerate = np.array(out["audio"][0]), 22050 # Example: 22050 Hz as common sampling rate
|
17 |
+
|
18 |
+
# Save the audio data to a temporary file
|
19 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmpfile:
|
20 |
+
sf.write(tmpfile.name, audio_data, samplerate)
|
21 |
+
# Return the path of the temporary audio file
|
22 |
+
return tmpfile.name
|
23 |
+
except Exception as e:
|
24 |
+
print(f"An error occurred: {e}")
|
25 |
+
return None
|
26 |
+
|
27 |
+
# Create the Gradio interface
|
28 |
+
iface = gr.Interface(fn=launch, inputs="text", outputs=gr.Audio())
|
29 |
+
|
30 |
+
# Launch the Gradio app
|
31 |
+
iface.launch()
|