luckyhookin commited on
Commit
b63d6d9
·
verified ·
1 Parent(s): 4d1795f
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -24,18 +24,19 @@ def preprocess_audio(audio_path):
24
  """Convert audio to mono, 16kHz WAV format suitable for pyannote."""
25
  try:
26
  if isinstance(audio_path, str):
27
- bytes = False
28
  else:
29
- bytes = True
30
 
31
  # Load audio with pydub
32
- audio = AudioSegment.from_file(BytesIO(audio_path) if bytes else audio_path)
33
  # Convert to mono and set sample rate to 16kHz
34
  audio = audio.set_channels(1).set_frame_rate(16000)
35
  # Export to temporary WAV file
36
- temp_wav = "temp_audio.wav"
37
- audio.export(temp_wav, format="wav")
38
- return temp_wav
 
39
  except Exception as e:
40
  raise ValueError(f"Error preprocessing audio: {str(e)}")
41
 
 
24
  """Convert audio to mono, 16kHz WAV format suitable for pyannote."""
25
  try:
26
  if isinstance(audio_path, str):
27
+ is_bytes = False
28
  else:
29
+ is_bytes = True
30
 
31
  # Load audio with pydub
32
+ audio = AudioSegment.from_file(BytesIO(audio_path) if is_bytes else audio_path)
33
  # Convert to mono and set sample rate to 16kHz
34
  audio = audio.set_channels(1).set_frame_rate(16000)
35
  # Export to temporary WAV file
36
+ buf = BytesIO()
37
+ audio.export(buf, format="wav")
38
+ buf.seek(0)
39
+ return buf
40
  except Exception as e:
41
  raise ValueError(f"Error preprocessing audio: {str(e)}")
42