Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,16 +36,19 @@ for message in st.session_state.messages:
|
|
36 |
if (prompt := st.chat_input("Your message")) or len(audio):
|
37 |
# If it's coming from the audio recorder transcribe the message with whisper.cpp
|
38 |
if len(audio) > 0:
|
39 |
-
#
|
40 |
if isinstance(audio, bytes):
|
41 |
-
#
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
else:
|
44 |
-
st.error("The audio data
|
45 |
-
|
46 |
-
|
47 |
-
if audio_segment:
|
48 |
-
prompt = inference(audio_segment)
|
49 |
|
50 |
# Display user message in chat message container
|
51 |
st.chat_message("user").markdown(prompt)
|
|
|
36 |
if (prompt := st.chat_input("Your message")) or len(audio):
|
37 |
# If it's coming from the audio recorder transcribe the message with whisper.cpp
|
38 |
if len(audio) > 0:
|
39 |
+
# Check if audio is a bytes object (raw audio data)
|
40 |
if isinstance(audio, bytes):
|
41 |
+
# Try to load audio from bytes using AudioSegment
|
42 |
+
try:
|
43 |
+
# Convert the raw byte data to an AudioSegment instance
|
44 |
+
audio_segment = AudioSegment.from_file(io.BytesIO(audio), format="wav")
|
45 |
+
prompt = inference(audio_segment)
|
46 |
+
except Exception as e:
|
47 |
+
st.error(f"Error processing audio: {e}")
|
48 |
+
prompt = "Sorry, there was an error processing your audio."
|
49 |
else:
|
50 |
+
st.error("The audio data is not in the expected format.")
|
51 |
+
prompt = "Sorry, the audio format is not correct."
|
|
|
|
|
|
|
52 |
|
53 |
# Display user message in chat message container
|
54 |
st.chat_message("user").markdown(prompt)
|