Cipher29 commited on
Commit
20a51d3
·
verified ·
1 Parent(s): 5292d46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import sounddevice as sd
4
+ import numpy as np
5
+
6
+ # Set the title with a colorful header
7
+ st.markdown("<h1 style='text-align: center; color: #FF6347;'>🎤 Text-to-Speech with Bark Model 🎶</h1>", unsafe_allow_html=True)
8
+
9
+ # Add a description with a stylish subtitle
10
+ st.markdown("<h3 style='text-align: center; color: #4682B4;'>Convert your text into lifelike speech instantly!</h3>", unsafe_allow_html=True)
11
+ st.markdown("---")
12
+
13
+ # Initialize the text-to-speech pipeline with the Bark model
14
+ synthesizer = pipeline("text-to-speech", model="suno/bark")
15
+
16
+ # Add an input text box with a vibrant background
17
+ text = st.text_area(
18
+ "Enter the text you want to convert to speech:",
19
+ placeholder="Type something interesting...",
20
+ height=150,
21
+ )
22
+
23
+ # Button to generate and play speech with a custom style
24
+ if st.button("🎙️ Convert to Speech"):
25
+ if text.strip() == "":
26
+ st.error("Please enter some text before converting!")
27
+ else:
28
+ with st.spinner("Generating speech... 🎶"):
29
+ # Generate speech
30
+ speech = synthesizer(text)
31
+
32
+ # Convert the audio data to 16-bit PCM format
33
+ audio_data = speech["audio"]
34
+ audio_data = np.int16(audio_data / np.max(np.abs(audio_data)) * 32767) # Normalize and convert to int16
35
+
36
+ # Play the generated audio immediately
37
+ sampling_rate = speech["sampling_rate"]
38
+ sd.play(audio_data, sampling_rate)
39
+ sd.wait() # Wait until the audio has finished playing
40
+
41
+ # Success message
42
+ st.success("🎉 Speech generation complete!")
43
+
44
+ # Add a colorful footer
45
+ st.markdown("<footer style='text-align: center; color: #708090; font-size: 12px;'>Created with ❤️ using Streamlit and Transformers</footer>", unsafe_allow_html=True)