MCPcopy
hub / github.com/Huanshere/VideoLingo / get_audio_duration

Function get_audio_duration

core/asr_backend/audio_preprocess.py:55–69  ·  view source on GitHub ↗

Get the duration of an audio file using ffmpeg.

(audio_file: str)

Source from the content-addressed store, hash-verified

53 rprint(f"[green]🎬➡️🎵 Converted <{video_file}> to <{_RAW_AUDIO_FILE}> with FFmpeg\n[/green]")
54
55def get_audio_duration(audio_file: str) -> float:
56 """Get the duration of an audio file using ffmpeg."""
57 cmd = ['ffmpeg', '-i', audio_file]
58 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
59 _, stderr = process.communicate()
60 output = stderr.decode('utf-8', errors='ignore')
61
62 try:
63 duration_str = [line for line in output.split('\n') if 'Duration' in line][0]
64 duration_parts = duration_str.split('Duration: ')[1].split(',')[0].split(':')
65 duration = float(duration_parts[0])*3600 + float(duration_parts[1])*60 + float(duration_parts[2])
66 except Exception as e:
67 print(f"[red]❌ Error: Failed to get audio duration: {e}[/red]")
68 duration = 0
69 return duration
70
71def split_audio(audio_file: str, target_len: float = 30*60, win: float = 60) -> List[Tuple[float, float]]:
72 ## 在 [target_len-win, target_len+win] 区间内用 pydub 检测静默,切分音频

Callers 6

adjust_audio_speedFunction · 0.90
process_rowFunction · 0.90
merge_chunksFunction · 0.90
tts_mainFunction · 0.90
siliconflow_fish_ttsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected