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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -36,9 +36,11 @@ 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
- # 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")
@@ -46,6 +48,12 @@ if (prompt := st.chat_input("Your message")) or len(audio):
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."
 
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
+ # Debugging: Check the type of the audio object
40
+ st.write(f"Audio Type: {type(audio)}")
41
+
42
+ # Handle the case where audio is in a byte format
43
  if isinstance(audio, bytes):
 
44
  try:
45
  # Convert the raw byte data to an AudioSegment instance
46
  audio_segment = AudioSegment.from_file(io.BytesIO(audio), format="wav")
 
48
  except Exception as e:
49
  st.error(f"Error processing audio: {e}")
50
  prompt = "Sorry, there was an error processing your audio."
51
+
52
+ # Handle the case where audio is an AudioSegment object
53
+ elif isinstance(audio, AudioSegment):
54
+ # Process it directly since it's already an AudioSegment
55
+ prompt = inference(audio)
56
+
57
  else:
58
  st.error("The audio data is not in the expected format.")
59
  prompt = "Sorry, the audio format is not correct."