richardorama commited on
Commit
ba285ca
·
verified ·
1 Parent(s): 255e1d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -130,35 +130,41 @@ else:
130
 
131
 
132
  from transformers import pipeline
133
- # # Load the pipeline
 
 
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
- DEFAULT_STATEMENT = ""
 
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
- if st.sidebar.button('TTS'):
144
- # Call your Summarize function here
145
- #st.write('\n\n')
146
-
147
- # Text to generate speech from
148
- text = "This is a sample text to be converted to speech."
149
-
150
- # Generate speech
151
- speech = tts(text)
152
-
153
- # Save the audio file
154
- speech.save("sample_tts.wav")
155
-
156
- st.sidebar.write('Text converted to speech')
157
- #summarize_statement(STATEMENT) # Directly pass the STATEMENT
 
 
 
 
158
  else:
159
- st.sidebar.button('TTS', disabled=True)
160
- #st.warning('👈 Please enter Statement!')
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 #################