Skip to content

Instantly share code, notes, and snippets.

@7m4mon
Created April 1, 2024 12:57
Show Gist options
  • Save 7m4mon/9e1e4183b0a1a4c11366d59420100238 to your computer and use it in GitHub Desktop.
Save 7m4mon/9e1e4183b0a1a4c11366d59420100238 to your computer and use it in GitHub Desktop.
#pydub のインポート
from pydub import AudioSegment
from pydub.silence import split_on_silence
import glob, os
files = glob.glob("C:/temp/*.mp3")
for file in files:
sound = AudioSegment.from_file(file, format='mp3')
dname = os.path.dirname(file)
fname = os.path.splitext(os.path.basename(file))[0]
print(file)#ファイル情報の表示
print(f'チャンネル数: {sound.channels}')
print(f'サンプリング周波数: {sound.frame_rate} Hz')
print(f'再生時間(秒): {sound.duration_seconds} 秒')
print(f'音量: {sound.dBFS} dB')
#mp3の分割(無音部分で区切る)
chunks = split_on_silence(sound, min_silence_len=1000, silence_thresh=-40, keep_silence=500, seek_step=(600000))
#分割したデータ毎にファイル出力
for i, chunk in enumerate(chunks):
chunk.export(dname + '/split_' + fname + '_' + str(i) + '.mp3', format='mp3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment