Parselmouth
Parselmouth is a Python library that provides a Pythonic interface to Praat, a widely used program for phonetic analysis. It wraps Praat's C++ core, allowing direct access to its functionalities for speech processing, acoustic analysis, and manipulation. The current version is 0.4.7, with minor releases and bug fixes occurring frequently.
Common errors
-
ERROR: Failed building wheel for praat-parselmouth
cause A pre-built wheel for your specific operating system and Python version was not found, and the system lacks the necessary C++ compiler or build tools (like CMake) to compile Parselmouth from source.fixInstall a C++ compiler (e.g., Visual Studio Build Tools on Windows, Xcode Command Line Tools on macOS, `build-essential` on Debian/Ubuntu, or `cmake` for all platforms) and try `pip install praat-parselmouth` again. -
AttributeError: module 'numpy' has no attribute 'array_api'
cause This error typically occurs when using Parselmouth versions older than 0.4.4 with a NumPy 2.x installation, due to changes in NumPy's internal structure.fixUpgrade Parselmouth to version 0.4.4 or higher: `pip install --upgrade praat-parselmouth`. -
ModuleNotFoundError: No module named 'parselmouth'
cause The `praat-parselmouth` library has not been installed, or the Python environment where it was installed is not currently active.fixInstall the library using `pip install praat-parselmouth`. If using virtual environments, ensure the correct environment is activated before running your script. -
TypeError: 'Sound' object is not callable
cause You are attempting to call a Parselmouth object (e.g., an instance of `Sound` or `Pitch`) as if it were a function, instead of using its methods or passing it to `parselmouth.praat.call()`.fixReview the Parselmouth documentation for the correct way to interact with objects. Use methods like `sound.to_pitch()` or pass objects to `parselmouth.praat.call(object, 'PraatCommand')`.
Warnings
- gotcha Installation of `praat-parselmouth` can fail if a pre-built wheel is not available for your specific Python version and operating system, requiring compilation from source. This needs a C++ compiler (e.g., MSVC, GCC, Clang) and CMake to be installed and configured on your system.
- breaking Versions of Parselmouth prior to 0.4.4 had compatibility issues with NumPy 2.x, leading to errors when processing audio data or accessing array properties.
- gotcha In older versions of Parselmouth (prior to 0.3.3), using `parselmouth.praat.call` or `parselmouth.praat.run` could lead to crashes when passing empty lists of objects or when returning objects that already existed in Praat's memory.
- gotcha While Parselmouth aims for broad Python compatibility, explicit support for newer Python versions (e.g., 3.10, 3.11) was added in specific minor releases (v0.4.1, v0.4.2). Using an older Parselmouth version with the very latest Python releases might encounter unexpected issues.
Install
-
pip install praat-parselmouth
Imports
- parselmouth
import parselmouth
- Sound
import parselmouth sound = parselmouth.Sound(...)
- praat
import parselmouth parselmouth.praat.call(...)
Quickstart
import parselmouth
import numpy as np
# Create a dummy sound object (e.g., a sine wave)
sr = 44100 # Sample rate
duration = 1.0 # seconds
t = np.linspace(0, duration, int(sr * duration), endpoint=False)
frequency = 440.0 # Hz
amplitude = 0.5
dummy_wave = amplitude * np.sin(2 * np.pi * frequency * t)
# Load the sound into Parselmouth
sound = parselmouth.Sound(dummy_wave, sr)
# Perform a basic Praat operation: extract pitch
pitch = sound.to_pitch()
# Print some information
print(f"Sound duration: {sound.duration:.2f} seconds")
print(f"First pitch value (at 0.1s): {pitch.get_value_at_time(0.1):.2f} Hz")
# Example of using a Praat command directly via parselmouth.praat.call
intensity = parselmouth.praat.call(sound, "To Intensity", 100, 0, False)
print(f"Mean intensity: {intensity.get_mean():.2f} dB")