Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mouseos/a850c3e9f4d7f83d80ffd95186a6913f to your computer and use it in GitHub Desktop.

Select an option

Save mouseos/a850c3e9f4d7f83d80ffd95186a6913f to your computer and use it in GitHub Desktop.
import os
import re
from pydub import AudioSegment
#パス
path = "audio/test"
for current_dir, sub_dirs, files_list in os.walk(path):
for file_name in files_list:
file_path=(os.path.join(current_dir,file_name))
extension=(re.sub('.*\.', '', file_path))
try:
sound = AudioSegment.from_file(os.path.join(current_dir,file_name), extension)
time = sound.duration_seconds # 再生時間(秒)
print(file_path)
print('再生時間:', time)
except Exception:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment