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

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

関連する外部ページ

前準備

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

Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.

手順

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    次のコマンドは,Python ランチャーとPython 3.10とGitをインストールし,Gitパスを通すものである.

    次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.

    winget install --scope machine Python.Launcher
    winget install --scope machine Python.Python.3.10
    winget install --scope machine Git.Git
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    

関連する外部ページ

サイト内の関連ページ

関連項目Python, Git バージョン管理システム, Git の利用

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

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. pip を用いてインストール
    pip install -U praat-parselmouth
    

動作確認

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. 公式ページから parselmouth のファイルをダウンロード
    cd /d c:%HOMEPATH%
    rmdir /s /q Parselmouth
    git clone --recursive https://github.com/YannickJadoul/Parselmouth
    
  3. numpy, matplotlib, seaborn のインストール
    pip install -U numpy matplotlib seaborn
    
  4. 振幅の表示

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

    次のコマンドを実行

    cd /d c:%HOMEPATH%
    cd parselmouth
    jupyter qtconsole
    

    次の 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")
    
  5. スペクトログラムの表示

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

    次のコマンドを実行

    cd /d c:%HOMEPATH%
    cd parselmouth
    jupyter qtconsole
    

    次の 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")