| import streamlit as st |
| from transformers import pipeline |
| import sounddevice as sd |
| import numpy as np |
|
|
| |
| st.markdown("<h1 style='text-align: center; color: #FF6347;'>๐ค Text-to-Speech with Bark Model ๐ถ</h1>", unsafe_allow_html=True) |
|
|
| |
| st.markdown("<h3 style='text-align: center; color: #4682B4;'>Convert your text into lifelike speech instantly!</h3>", unsafe_allow_html=True) |
| st.markdown("---") |
|
|
| |
| synthesizer = pipeline("text-to-speech", model="suno/bark") |
|
|
| |
| text = st.text_area( |
| "Enter the text you want to convert to speech:", |
| placeholder="Type something interesting...", |
| height=150, |
| ) |
|
|
| |
| if st.button("๐๏ธ Convert to Speech"): |
| if text.strip() == "": |
| st.error("Please enter some text before converting!") |
| else: |
| with st.spinner("Generating speech... ๐ถ"): |
| |
| speech = synthesizer(text) |
|
|
| |
| audio_data = speech["audio"] |
| audio_data = np.int16(audio_data / np.max(np.abs(audio_data)) * 32767) |
|
|
| |
| sampling_rate = speech["sampling_rate"] |
| sd.play(audio_data, sampling_rate) |
| sd.wait() |
|
|
| |
| st.success("๐ Speech generation complete!") |
|
|
| |
| st.markdown("<footer style='text-align: center; color: #708090; font-size: 12px;'>Created with โค๏ธ using Streamlit and Transformers</footer>", unsafe_allow_html=True) |
|
|