Parselmouthでの音声処理を行う 3.


以前の投稿で, Parselmouthというライブラリについてまとめた. 今回はさらに, 音声をスペクトログラムで表示するコードを記述する.

# ---------------------------------------------------------
# スペクトログラムの生成
# ---------------------------------------------------------
spectrogram = snd.to_spectrogram()
# このオブジェクトには「あいうえお」それぞれの周波数特性が時間順に並んでいます
spectrogram = snd.to_spectrogram()

# 時間軸(X)と周波数軸(Y)のグリッドデータを取得
X, Y = spectrogram.x_grid(), spectrogram.y_grid()

# パワーの値をデシベル(dB)に変換
sg_db = 10 * np.log10(spectrogram.values)

# グラフの描画設定
plt.figure(figsize=(10, 4))

plt.pcolormesh(X, Y, sg_db, vmin=sg_db.max() - 70, cmap='afmhot')

plt.ylim([spectrogram.ymin, spectrogram.ymax])
plt.xlabel("Time [s]")
plt.ylabel("Frequency [Hz]")
plt.title("Spectrogram")
plt.colorbar(label="Power (dB)")
plt.tight_layout()
plt.show()

参考文献

  • Jadoul, Y., Thompson, B., & de Boer, B. (2018). Introducing Parselmouth: A Python interface to Praat. Journal of Phonetics, 71, 1-15. https://doi.org/10.1016/j.wocn.2018.07.001
  • Boersma, P., & Weenink, D. (2021). Praat: doing phonetics by computer Computer program. Version 6.1.38, retrieved 2 January 2021 from http://www.praat.org/

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です