金子邦彦研究室人工知能Windows で動く人工知能関係 Pythonアプリケーション,オープンソースソフトウエア)Parselmouth のインストールと動作確認(Praat 用の Python ライブラリ,振幅やスペクトログラムの表示など)(Python を使用)(Windows 上)

Parselmouth のインストールと動作確認(Praat 用の Python ライブラリ,振幅やスペクトログラムの表示など)(Python を使用)(Windows 上)

スペクトログラムは,周波数と時間を,縦横の軸とするグラフ.強度を色や明るさで表すことが多い.

関連する外部ページ

前準備

Git のインストール(Windows 上)

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Python の公式ページ: https://www.python.org/

parselmouth のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. pip を用いてインストール

    pip install -U praat-parselmouth
    

    [image]

動作確認

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. 公式ページから parselmouth のファイルをダウンロード

    cd %HOMEPATH%
    rmdir /s /q Parselmouth
    git clone --recursive https://github.com/YannickJadoul/Parselmouth
    

    [image]
  3. numpy, matplotlib, seaborn のインストール

    pip install -U numpy matplotlib seaborn
    

    [image]
  4. 振幅の表示

    公式ページに記載のプログラムを使用

    次のコマンドを実行

    cd %HOMEPATH%
    cd parselmouth
    jupyter qtconsole
    

    [image]

    次の Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsoleJupyter ノートブック (Jupyter Notebook) の利用が便利である.

    Python プログラムの実行: 別ページ »で説明

    Python のまとめ: 別ページ »にまとめ

    import parselmouth
    
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.set() # Use seaborn's default style to make attractive graphs
    
    # Plot nice figures using Python's "standard" matplotlib library
    snd = parselmouth.Sound("docs/examples/audio/the_north_wind_and_the_sun.wav")
    plt.figure()
    plt.plot(snd.xs(), snd.values.T)
    plt.xlim([snd.xmin, snd.xmax])
    plt.xlabel("time [s]")
    plt.ylabel("amplitude")
    plt.show() # or plt.savefig("sound.png"), or plt.savefig("sound.pdf")
    

    [image]
  5. スペクトログラムの表示

    公式ページに記載のプログラムを使用

    次のコマンドを実行

    cd %HOMEPATH%
    cd parselmouth
    jupyter qtconsole
    

    [image]

    次の Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsoleJupyter ノートブック (Jupyter Notebook) の利用が便利である.

    import parselmouth
    
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.set() # Use seaborn's default style to make attractive graphs
    
    def draw_spectrogram(spectrogram, dynamic_range=70):
        X, Y = spectrogram.x_grid(), spectrogram.y_grid()
        sg_db = 10 * np.log10(spectrogram.values)
        plt.pcolormesh(X, Y, sg_db, vmin=sg_db.max() - dynamic_range, cmap='afmhot')
        plt.ylim([spectrogram.ymin, spectrogram.ymax])
        plt.xlabel("time [s]")
        plt.ylabel("frequency [Hz]")
    
    def draw_intensity(intensity):
        plt.plot(intensity.xs(), intensity.values.T, linewidth=3, color='w')
        plt.plot(intensity.xs(), intensity.values.T, linewidth=1)
        plt.grid(False)
        plt.ylim(0)
        plt.ylabel("intensity [dB]")
    
    # Plot nice figures using Python's "standard" matplotlib library
    snd = parselmouth.Sound("docs/examples/audio/the_north_wind_and_the_sun.wav")
    
    intensity = snd.to_intensity()
    spectrogram = snd.to_spectrogram()
    plt.figure()
    draw_spectrogram(spectrogram)
    plt.twinx()
    draw_intensity(intensity)
    plt.xlim([snd.xmin, snd.xmax])
    plt.show() # or plt.savefig("spectrogram.pdf")
    

    [image]