Skip to content
Praat in Python, the Pythonic way
C++ Python CMake Shell C
Branch: master
Clone or download

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Changing links to docs from latest to stable version in README and Gi… Jun 25, 2019
binder Adding and cleaning up requirements.txt for various scenarios (standa… Mar 29, 2019
docs Dropping manylinux1 support Feb 19, 2020
praat Fix "test_praat_dwtest[test_gammatonefilter.praat]" failure due to li… Jan 21, 2020
pybind11 Split pickle in enum_::enum_ back into __setstate__ and __getstate__,… Jan 27, 2020
res Happy 2020! (bis) Jan 2, 2020
src Fix default value of very_accurate parameter in Sound.to_pitch_ac and… Feb 14, 2020
tests Adding keep_cwd keyword-argument to parselmouth.praat.run_file Jan 25, 2020
.appveyor.yml Running Praat tests on some CI jobs Jan 3, 2020
.gitattributes Adding .gitattributes to exclude praat/ and pybind11/ subdirs from th… Nov 5, 2018
.gitignore Adding first version of tests Jul 6, 2018
.readthedocs.yml Updated ReadTheDocs configuration to version 2 Aug 23, 2019
.travis.yml Dropping manylinux1 support Feb 19, 2020
CHANGELOG.md Removing support for 3.4 Dec 23, 2019
CMakeLists.txt Merge branch 'stable' Jan 2, 2020
CODE_OF_CONDUCT.md Adding CODE_OF_CONDUCT.md Apr 1, 2019
LICENSE Adding GPLv3 to LICENSE and GPL preamble to all files Jun 6, 2017
MANIFEST.in Adding and cleaning up requirements.txt for various scenarios (standa… Mar 29, 2019
README.md Merge branch 'stable' Feb 17, 2020
pytest.ini Splitting up single test running Praat's tests into multiple parts, a… Jan 17, 2020
requirements.txt Adding and cleaning up requirements.txt for various scenarios (standa… Mar 29, 2019
setup.cfg Adding manifest-check and test build of source distribution to Travis… Mar 27, 2019
setup.py Converting setup.py's long_description to Markdown Jan 3, 2020

README.md

Parselmouth

Parselmouth - Praat in Python, the Pythonic way

PyPI Gitter chat Travis CI status AppVeyor status ReadTheDocs status License Launch Binder

Parselmouth is a Python library for the Praat software.

Though other attempts have been made at porting functionality from Praat to Python, Parselmouth is unique in its aim to provide a complete and Pythonic interface to the internal Praat code. While other projects either wrap Praat's scripting language or reimplementing parts of Praat's functionality in Python, Parselmouth directly accesses Praat's C/C++ code (which means the algorithms and their output are exactly the same as in Praat) and provides efficient access to the program's data, but also provides an interface that looks no different from any other Python library.

Drop by our Gitter chat room or post a message to our Google discussion group if you have any question, remarks, or requests!

Try out Parselmouth online, in interactive Jupyter notebooks on Binder.

Warning: The upcoming release of Parselmouth 0.4.0 will be the last version supporting Python 2. Python 2 has reached End Of Life on January 1, 2020, and is officially not supported anymore: see https://python3statement.org/. It is strongly suggested to move to Python 3, to be able to use new Parselmouth functionality after the 0.4.0 release.

Installation

Parselmouth can be installed like any other Python library, using (a recent version of) the Python package manager pip, on Linux, macOS, and Windows:

pip install praat-parselmouth

or, to update your installed version to the latest release:

pip install -U praat-parselmouth

For more detailed instructions, please refer to the documentation.

Example usage

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

docs/images/example_sound.png

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]")

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

docs/images/example_spectrogram.png

def draw_pitch(pitch):
    # Extract selected pitch contour, and
    # replace unvoiced samples by NaN to not plot
    pitch_values = pitch.selected_array['frequency']
    pitch_values[pitch_values==0] = np.nan
    plt.plot(pitch.xs(), pitch_values, 'o', markersize=5, color='w')
    plt.plot(pitch.xs(), pitch_values, 'o', markersize=2)
    plt.grid(False)
    plt.ylim(0, pitch.ceiling)
    plt.ylabel("fundamental frequency [Hz]")

pitch = snd.to_pitch()
# If desired, pre-emphasize the sound fragment before calculating the spectrogram
pre_emphasized_snd = snd.copy()
pre_emphasized_snd.pre_emphasize()
spectrogram = pre_emphasized_snd.to_spectrogram(window_length=0.03, maximum_frequency=8000)
plt.figure()
draw_spectrogram(spectrogram)
plt.twinx()
draw_pitch(pitch)
plt.xlim([snd.xmin, snd.xmax])
plt.show() # or plt.savefig("spectrogram_0.03.pdf")

docs/images/example_spectrogram_0.03.png

# Find all .wav files in a directory, pre-emphasize and save as new .wav and .aiff file
import parselmouth

import glob
import os.path

for wave_file in glob.glob("audio/*.wav"):
    print("Processing {}...".format(wave_file))
    s = parselmouth.Sound(wave_file)
    s.pre_emphasize()
    s.save(os.path.splitext(wave_file)[0] + "_pre.wav", 'WAV') # or parselmouth.SoundFileFormat.WAV instead of 'WAV'
    s.save(os.path.splitext(wave_file)[0] + "_pre.aiff", 'AIFF')

More examples of different use cases of Parselmouth can be found in the documentation's examples section.

Documentation

Documentation is available at ReadTheDocs, including the API reference of Parselmouth.

Development

Currently, the actual project and Parselmouth's code is not very well documented. Or well, hardly documented at all. That is planned to still change in order to allow for easier contribution to this open source project. Until that day in some undefined future, if you want to contribute to Parselmouth, do let me know on Gitter or by email, and I will very gladly guide you through the project and help you get started.

Briefly summarized, Parselmouth is built using cmake. Next to that, to manually build Parselmouth, the only requirement is a modern C++ compiler supporting the C++17 standard.

Acknowledgements

  • Parselmouth builds on the extensive code base of Praat by Paul Boersma, which actually implements the huge variety of speech processing and phonetic algorithms that can now be accessed through Parselmouth.
  • In order to do so, Parselmouth makes use of the amazing pybind11 library, allowing to expose the C/C++ functionality of Praat as a Python interface.
  • Special thanks go to Bill Thompson and Robin Jadoul for their non-visible-in-history but very valuable contributions.

License

You can’t perform that action at this time.