richardorama
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -130,35 +130,41 @@ else:
|
|
130 |
|
131 |
|
132 |
from transformers import pipeline
|
133 |
-
|
|
|
|
|
134 |
tts = pipeline("text-to-speech")
|
135 |
|
136 |
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>TTS - Pipeline</h3>", unsafe_allow_html=True)
|
137 |
-
|
|
|
138 |
# Create a text area for user input
|
139 |
STATEMENT = st.sidebar.text_area('Enter Text', DEFAULT_STATEMENT, height=150)
|
140 |
|
141 |
# Enable the button only if there is text in the TTS variable
|
142 |
if STATEMENT:
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
158 |
else:
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
|
163 |
|
164 |
# ################ CHAT BOT - main area #################
|
|
|
130 |
|
131 |
|
132 |
from transformers import pipeline
|
133 |
+
import sounddevice as sd # Import for audio playback (optional)
|
134 |
+
|
135 |
+
# Load the pipeline
|
136 |
tts = pipeline("text-to-speech")
|
137 |
|
138 |
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>TTS - Pipeline</h3>", unsafe_allow_html=True)
|
139 |
+
|
140 |
+
DEFAULT_STATEMENT = "This is a sample text to be converted to speech."
|
141 |
# Create a text area for user input
|
142 |
STATEMENT = st.sidebar.text_area('Enter Text', DEFAULT_STATEMENT, height=150)
|
143 |
|
144 |
# Enable the button only if there is text in the TTS variable
|
145 |
if STATEMENT:
|
146 |
+
if st.sidebar.button('TTS'):
|
147 |
+
# Text to generate speech from
|
148 |
+
text = STATEMENT # Use the user input from STATEMENT
|
149 |
+
|
150 |
+
# Generate speech
|
151 |
+
speech = tts(text)
|
152 |
+
|
153 |
+
# Access the audio waveform from the dictionary (assuming key name is 'waveform')
|
154 |
+
audio_data = speech['waveform']
|
155 |
+
|
156 |
+
# Optional: Save the audio to a file (uncomment if needed)
|
157 |
+
# sd.write(audio_data, samplerate=speech['sampling_rate']) # Adjust samplerate if necessary
|
158 |
+
# with open("sample_tts.wav", "wb") as f:
|
159 |
+
# f.write(audio_data)
|
160 |
+
|
161 |
+
# Optional: Play the audio directly in Streamlit (uncomment if needed)
|
162 |
+
sd.play(audio_data, samplerate=speech['sampling_rate']) # Adjust samplerate if necessary
|
163 |
+
|
164 |
+
st.sidebar.write('Text converted to speech')
|
165 |
else:
|
166 |
+
st.sidebar.button('TTS', disabled=True)
|
167 |
+
# st.warning(' Please enter Statement!')
|
|
|
168 |
|
169 |
|
170 |
# ################ CHAT BOT - main area #################
|