Spaces:
Running on Zero
Running on Zero
fix bug
Browse files
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 |
-
|
| 28 |
else:
|
| 29 |
-
|
| 30 |
|
| 31 |
# Load audio with pydub
|
| 32 |
-
audio = AudioSegment.from_file(BytesIO(audio_path) if
|
| 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 |
-
|
| 37 |
-
audio.export(
|
| 38 |
-
|
|
|
|
| 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 |
|