Spaces:
Runtime error
Runtime error
Switched to gTTs for text-to-speech
Browse files
app.py
CHANGED
@@ -10,6 +10,10 @@ import tempfile
|
|
10 |
import streamlit as st
|
11 |
from PIL import Image
|
12 |
|
|
|
|
|
|
|
|
|
13 |
master_prompt = """
|
14 |
As a Natural Farming Fertilizers Assistant, you will assist the user with any farming related question, always willing to answer any question and provide useful organic farming advice in the following format.
|
15 |
' ' '
|
@@ -110,49 +114,11 @@ def launch_bot():
|
|
110 |
audio_result = st.button("Convert to Audio 🔊")
|
111 |
if audio_result:
|
112 |
# with st.chat_message("assistant"):
|
113 |
-
st.write("Converting text to speech. This may take a few minutes.")
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
synthesiser = pipeline("text-to-speech", "suno/bark-small")
|
119 |
-
|
120 |
-
speech = synthesiser(response, forward_params={"do_sample": True})
|
121 |
-
|
122 |
-
# write to temp file: the scipy wav write bark_out.wav
|
123 |
-
fp.write(scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"]))
|
124 |
-
|
125 |
-
with st.chat_message("assistant"):
|
126 |
-
with st.spinner("Thinking..."):
|
127 |
-
# ST interface for audio
|
128 |
-
print("Now we try to display the audio file in the app")
|
129 |
-
|
130 |
-
# Temp file access
|
131 |
-
fp.seek(0)
|
132 |
-
audio_file = fp.read('bark_out.wav', 'rb')
|
133 |
-
|
134 |
-
audio_bytes = audio_file.read()
|
135 |
-
|
136 |
-
# Close and delete temp file
|
137 |
-
fp.close()
|
138 |
-
|
139 |
-
st.session_state.messages.append({"role": "assistant", "content": st.audio(audio_bytes, format='audio/wav')})
|
140 |
-
#audio_convert = st.audio(audio_bytes, format='audio/wav')
|
141 |
-
#st.session_state.messages.append(audio_convert)
|
142 |
-
#sample_rate = 44100 # 44100 samples per second
|
143 |
-
#seconds = 2 # Note duration of 2 seconds
|
144 |
-
|
145 |
-
#frequency_la = 440 # Our played note will be 440 Hz
|
146 |
-
|
147 |
-
# Generate array with seconds*sample_rate steps, ranging between 0 and seconds
|
148 |
-
#t = np.linspace(0, seconds, seconds * sample_rate, False)
|
149 |
-
|
150 |
-
# Generate a 440 Hz sine wave
|
151 |
-
#note_la = np.sin(frequency_la * t * 2 * np.pi)
|
152 |
-
#st.audio(note_la, sample_rate=sample_rate)
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
|
157 |
if __name__ == "__main__":
|
158 |
launch_bot()
|
|
|
10 |
import streamlit as st
|
11 |
from PIL import Image
|
12 |
|
13 |
+
from gtts import gTTS
|
14 |
+
from io import BytesIO
|
15 |
+
|
16 |
+
|
17 |
master_prompt = """
|
18 |
As a Natural Farming Fertilizers Assistant, you will assist the user with any farming related question, always willing to answer any question and provide useful organic farming advice in the following format.
|
19 |
' ' '
|
|
|
114 |
audio_result = st.button("Convert to Audio 🔊")
|
115 |
if audio_result:
|
116 |
# with st.chat_message("assistant"):
|
117 |
+
st.write("Converting text to speech. This may take a few minutes.")
|
118 |
+
sound_file = BytesIO()
|
119 |
+
tts = gTTS('Add text-to-speech to your app', lang='en')
|
120 |
+
tts.write_to_fp(sound_file)
|
121 |
+
st.audio(sound_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
if __name__ == "__main__":
|
124 |
launch_bot()
|