Parselmouth のインストールと動作確認(Praat 用の Python ライブラリ,振幅やスペクトログラムの表示など)(Python を使用)(Windows 上)
スペクトログラムは,周波数と時間を,縦横の軸とするグラフ.強度を色や明るさで表すことが多い.
【関連する外部ページ】
- GitHub のページ: https://github.com/YannickJadoul/Parselmouth
前準備
Python 3.12,Git のインストール(Windows 上)
Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.
【手順】
- Windows で,コマンドプロンプトを管理者権限で起動する(手順:Windowsキーまたはスタートメニュー,「cmd」と入力,右クリックメニューなどで「管理者として実行」を選択)
次のコマンドを実行
次のコマンドは,Python ランチャーとPython 3.12とGitをインストールし,Gitにパスを通すものである.
次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f REM Python, Git をシステム領域にインストール winget install --scope machine --id Python.Python.3.12 --id Python.Launcher --id Git.Git -e --silent REM Python のパス set "INSTALL_PATH=C:\Program Files\Python312" echo %PATH% | find /i "%INSTALL_PATH%" >nul if errorlevel 1 setx PATH "%PATH%;%INSTALL_PATH%" /M >nul echo %PATH% | find /i "%INSTALL_PATH%\Scripts" >nul if errorlevel 1 setx PATH "%PATH%;%INSTALL_PATH%\Scripts" /M >nul REM Git のパス set "NEW_PATH=C:\Program Files\Git\cmd" if exist "%NEW_PATH%" echo %PATH% | find /i "%NEW_PATH%" >nul if exist "%NEW_PATH%" if errorlevel 1 setx PATH "%PATH%;%NEW_PATH%" /M >nul
【関連する外部ページ】
- Python の公式ページ: https://www.python.org/
- Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連項目】 Python, Git バージョン管理システム, Git の利用
parselmouth のインストール(Windows 上)
- Windows で,コマンドプロンプトを管理者権限で起動する(手順:Windowsキーまたはスタートメニュー,「cmd」と入力,右クリックメニューなどで「管理者として実行」を選択)
- pip を用いてインストール
pip install -U praat-parselmouth
動作確認
- Windows で,コマンドプロンプトを管理者権限で起動する(手順:Windowsキーまたはスタートメニュー,「cmd」と入力,右クリックメニューなどで「管理者として実行」を選択)
- 公式ページから parselmouth のファイルをダウンロード
cd /d c:%HOMEPATH% rmdir /s /q Parselmouth git clone --recursive https://github.com/YannickJadoul/Parselmouth
- numpy, matplotlib, seaborn のインストール
pip install -U numpy matplotlib seaborn
- 振幅の表示
公式ページに記載のプログラムを使用
次のコマンドを実行
cd /d c:%HOMEPATH% cd parselmouth jupyter qtconsole
次の Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (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 # 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")
- スペクトログラムの表示
公式ページに記載のプログラムを使用
次のコマンドを実行
cd /d c:%HOMEPATH% cd parselmouth jupyter qtconsole
次の Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (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")