Spaces:
Sleeping
Sleeping
Demosthene-OR
commited on
Commit
•
648c69e
1
Parent(s):
b05362d
....
Browse files- .gitignore +2 -0
- tabs/chatbot_tab.py +30 -15
.gitignore
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
# DotEnv configuration
|
2 |
.env
|
|
|
|
|
3 |
|
|
|
1 |
# DotEnv configuration
|
2 |
.env
|
3 |
+
#
|
4 |
+
*.pyc
|
5 |
|
tabs/chatbot_tab.py
CHANGED
@@ -209,27 +209,42 @@ def run():
|
|
209 |
if audio_bytes:
|
210 |
st.write("**"+tr("Vendeur")+" :**\n")
|
211 |
# Fonction pour générer et jouer le texte en speech
|
212 |
-
st.audio(audio_bytes, format="audio/wav")
|
213 |
try:
|
214 |
-
|
215 |
-
|
|
|
|
|
216 |
|
217 |
-
|
218 |
-
|
219 |
|
220 |
-
|
221 |
-
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
# Transcription Whisper (si result a été préalablement calculé)
|
232 |
st.write("**Vendeur :** "+query)
|
|
|
233 |
|
234 |
if query != "":
|
235 |
input_messages = [HumanMessage(query)]
|
|
|
209 |
if audio_bytes:
|
210 |
st.write("**"+tr("Vendeur")+" :**\n")
|
211 |
# Fonction pour générer et jouer le texte en speech
|
212 |
+
st.audio(audio_bytes, format="audio/wav", autoplay=False)
|
213 |
try:
|
214 |
+
detection = False
|
215 |
+
if detection:
|
216 |
+
# Create a BytesIO object from the audio stream
|
217 |
+
audio_stream_bytesio = io.BytesIO(audio_bytes)
|
218 |
|
219 |
+
# Read the WAV stream using wavio
|
220 |
+
wav = wavio.read(audio_stream_bytesio)
|
221 |
|
222 |
+
# Extract the audio data from the wavio.Wav object
|
223 |
+
audio_data = wav.data
|
224 |
|
225 |
+
# Convert the audio data to a NumPy array
|
226 |
+
audio_input = np.array(audio_data, dtype=np.float32)
|
227 |
+
audio_input = np.mean(audio_input, axis=1)/32768
|
228 |
+
|
229 |
+
result = model_speech.transcribe(audio_input)
|
230 |
+
Lang_detected = result["language"]
|
231 |
+
query = result["text"]
|
232 |
+
st.write(tr("Langue détectée")+" : "+Lang_detected)
|
233 |
+
|
234 |
+
else:
|
235 |
+
# Avec l'aide de la bibliothèque speech_recognition de Google
|
236 |
+
Lang_detected = "fr"
|
237 |
+
# Transcription google
|
238 |
+
audio_stream = sr.AudioData(audio_bytes, 32000, 2)
|
239 |
+
r = sr.Recognizer()
|
240 |
+
query = r.recognize_google(audio_stream, language = Lang_detected)
|
241 |
+
|
242 |
+
|
243 |
+
|
244 |
+
|
245 |
# Transcription Whisper (si result a été préalablement calculé)
|
246 |
st.write("**Vendeur :** "+query)
|
247 |
+
st.write("")
|
248 |
|
249 |
if query != "":
|
250 |
input_messages = [HumanMessage(query)]
|