Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklesworthstone committed May 30, 2024
1 parent bb1c40b commit cecf403
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions service_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import psutil
import glob
import json
import io
import zipfile
import tempfile
import traceback
Expand Down Expand Up @@ -953,8 +954,14 @@ async def get_or_compute_transcript(file: UploadFile,
else:
return {"status": "already processing"}

def get_audio_duration_seconds(file_path: str) -> float:
audio = MutagenFile(file_path)
def get_audio_duration_seconds(audio_input) -> float:
if isinstance(audio_input, bytes):
audio_file = io.BytesIO(audio_input)
audio = MutagenFile(audio_file)
elif isinstance(audio_input, str):
audio = MutagenFile(audio_input)
else:
raise ValueError("audio_input must be either bytes or a file path string.")
if audio is None or not hasattr(audio.info, 'length'):
raise ValueError("Could not determine the length of the audio file.")
return audio.info.length
Expand Down

0 comments on commit cecf403

Please sign in to comment.