Spaces:
Sleeping
Sleeping
Nikhil0987
commited on
Commit
•
1e3611e
1
Parent(s):
f072cf5
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
import scipy.io.wavfile
|
5 |
+
import numpy as np
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Load the text-to-speech pipeline
|
9 |
+
synthesizer = pipeline("text-to-speech", model="suno/bark")
|
10 |
+
|
11 |
+
# Streamlit app
|
12 |
+
st.title("Text-to-Speech with Suno/Bark Model")
|
13 |
+
|
14 |
+
# Text input from the user
|
15 |
+
text = st.text_area("Enter the text you want to convert to speech:", "")
|
16 |
+
|
17 |
+
if st.button("Generate Speech"):
|
18 |
+
if text:
|
19 |
+
with st.spinner("Generating speech..."):
|
20 |
+
# Generate speech from text
|
21 |
+
speech = synthesizer(text, forward_params={"do_sample": True})
|
22 |
+
|
23 |
+
# Save the speech as a WAV file
|
24 |
+
output_path = "output.wav"
|
25 |
+
scipy.io.wavfile.write(output_path, rate=speech["sampling_rate"], data=np.array(speech["audio"]))
|
26 |
+
|
27 |
+
st.success("Speech generated successfully!")
|
28 |
+
|
29 |
+
# Provide options to play and download the audio file
|
30 |
+
audio_file = open(output_path, "rb").read()
|
31 |
+
st.audio(audio_file, format="audio/wav")
|
32 |
+
st.download_button(label="Download WAV file", data=audio_file, file_name="output.wav", mime="audio/wav")
|
33 |
+
else:
|
34 |
+
st.error("Please enter some text to generate speech.")
|