suno_bark / app.py
Nikhil0987's picture
Update app.py
1e3611e verified
raw
history blame contribute delete
1.24 kB
import streamlit as st
from transformers import pipeline
import scipy.io.wavfile
import numpy as np
import os
# Load the text-to-speech pipeline
synthesizer = pipeline("text-to-speech", model="suno/bark")
# Streamlit app
st.title("Text-to-Speech with Suno/Bark Model")
# Text input from the user
text = st.text_area("Enter the text you want to convert to speech:", "")
if st.button("Generate Speech"):
if text:
with st.spinner("Generating speech..."):
# Generate speech from text
speech = synthesizer(text, forward_params={"do_sample": True})
# Save the speech as a WAV file
output_path = "output.wav"
scipy.io.wavfile.write(output_path, rate=speech["sampling_rate"], data=np.array(speech["audio"]))
st.success("Speech generated successfully!")
# Provide options to play and download the audio file
audio_file = open(output_path, "rb").read()
st.audio(audio_file, format="audio/wav")
st.download_button(label="Download WAV file", data=audio_file, file_name="output.wav", mime="audio/wav")
else:
st.error("Please enter some text to generate speech.")