cvsa/ml/lab/utils/audio.py
alikia2x 636c5e25cb
ref: move ML stuff
add: .idea to VCS, the refactor guide
2025-03-29 14:13:15 +08:00

16 lines
469 B
Python

from pydub import AudioSegment
def get_audio_duration(file_path):
"""
读取音频文件并获取其时长(秒数)。
:param file_path: 音频文件的路径
:return: 音频文件的时长(秒数)
"""
try:
audio = AudioSegment.from_file(file_path)
duration_in_seconds = len(audio) / 1000.0
return duration_in_seconds
except Exception as e:
print(f"Error reading audio file: {e}")
return None