shukdevdatta123 commited on
Commit
285b197
·
verified ·
1 Parent(s): 4a48709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -36,9 +36,16 @@ 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
- # Convert audio (from audiorecorder) to AudioSegment
40
- audio_segment = AudioSegment.from_file(io.BytesIO(audio), format="wav")
41
- prompt = inference(audio_segment)
 
 
 
 
 
 
 
42
 
43
  # Display user message in chat message container
44
  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
+ # 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)