Pythonモジュール「pydub」でmp3、wavから「再生時間」「サンプリングレート」「チャンネル数」を取得する方法についてソースコード付きでまとめました。
再生時間、サンプリングレート、チャンネル数
Pythonモジュール「pydub」では、mp3、wavファイルの再生時間、サンプリングレート、チャンネル数を抽出できます。
サンプルコード
サンプルプログラムのソースコードです。
# -*- coding: utf-8 -*-
from pydub import AudioSegment
# 音声ファイルの読み込み
sound = AudioSegment.from_file("input.mp3", "mp3")
# 情報の取得
time = sound.duration_seconds # 再生時間(秒)
rate = sound.frame_rate # サンプリングレート(Hz)
channel = sound.channels # チャンネル数(1:mono, 2:stereo)
# 情報の表示
print('チャンネル数:', channel)
print('サンプリングレート:', rate)
print('再生時間:', time)
| – | 関連記事 |
|---|---|
| 1 | ■【Python/pydub】音声ファイル処理 ■Python入門 基本文法 |

コメント