shukdevdatta123 commited on
Commit
7ec85f9
·
verified ·
1 Parent(s): 285b197

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
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
- # Ensure that the `audio` is a raw bytes object
40
  if isinstance(audio, bytes):
41
- # Convert the raw byte data to an AudioSegment instance
42
- audio_segment = AudioSegment.from_file(io.BytesIO(audio), format="wav")
 
 
 
 
 
 
43
  else:
44
- st.error("The audio data format is not correct.")
45
- audio_segment = None
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)