Skip to main content

Praat in Python, the Pythonic way

Project description

# Parselmouth - Praat in Python, the Pythonic way
**Parselmouth** is a Python library for the [Praat](http://www.praat.org) 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.

Please note that Parselmouth is currently in premature state and in active development. While the amount of functionality that is currently present is not huge, more will be added over the next few months.

Drop by our [Gitter chat room](https://gitter.im/PraatParselmouth/Lobby), if you have any question, remarks, or requests!



## Installation
Parselmouth can be installed like any other Python library, using (a recent version of) the Python package manager `pip`:
```
pip install praat-parselmouth
```
or, in case you have multiple installations of Python and don't know which `pip` belongs to which Python version *(looking at you, OS X)*:
```python
import pip
pip.main(['install', 'praat-parselmouth'])
```

If this results in an error, try updating `pip` to the latest version by running
```
pip install -U pip
```
If you do not have `pip` installed, you follow these instructions to install pip: https://pip.pypa.io/en/stable/installing/

### Troubleshooting
Since the project is still in an early development phase, it is possible that you run into more problems when trying to install or use Parselmouth. If you would do so after trying this, please drop by the [Gitter chat room](https://gitter.im/PraatParselmouth/Lobby), log a GitHub issue, or write [me](mailto:Yannick.Jadoul@ai.vub.ac.be) a quick email. We are of course very grateful for you feedback!

## Example usage
```Python
import parselmouth

import numpy as np
import matplotlib.pyplot as plt
import seaborn

# Plot nice figures using Python’s “standard” matplotlib library
snd = parselmouth.Sound("~/z6a.WAVE")
max_t = snd.num_samples / snd.sampling_frequency
plt.plot(np.linspace(0, max_t, snd.num_samples), snd.values)
plt.xlim([0, max_t])
plt.xlabel("time [s]")
plt.ylabel("amplitude")
plt.show() # or plt.savefig("sound.pdf)
```
![example_sound.png](res/images/example_sound.png)
```Python
def draw_spectrogram(spectrogram, max_t, max_f=5000, dynamic_range=70):
X = np.linspace(0, max_t, spectrogram.values.shape[0])
Y = np.linspace(0, max_f, spectrogram.values.shape[1])
spectrogram_db = 10 * np.log10(spectrogram.values.T)
plt.pcolormesh(X, Y, sg_db, vmin=spectrogram_db.max() - dynamic_range, cmap='afmhot')
plt.xlabel("time [s]")
plt.ylabel("frequency [Hz]")

def draw_intensity(intensity, max_t):
plt.plot(np.linspace(0, max_t, intensity.values.shape[0]), intensity.values, linewidth=3, color='w')
plt.plot(np.linspace(0, max_t, intensity.values.shape[0]), intensity.values, linewidth=1)
plt.grid(False)
plt.xlim([0, max_t])
plt.ylim(0)
plt.ylabel("intensity [dB]")

intensity = snd.to_intensity()

spectrogram = snd.to_spectrogram()
draw_spectrogram(spectrogram, max_t)
plt.twinx()
draw_intensity(intensity, max_t)
plt.show() # or plt.savefig("spectrogram.pdf)
```
![example_spectrogram.png](res/images/example_spectrogram.png)
```Python
spectrogram = snd.to_spectrogram(window_length=0.05)
draw_spectrogram(spectrogram, max_t)
plt.show() # or plt.savefig("spectrogram_0.05.pdf)
```
![example_spectrogram_0.05.png](res/images/example_spectrogram_0.05.png)
```Python
# Find all .wav files in a directory, pre-emphasize and save as new .wav and .aiff file
import glob
import os.path
from parselmouth import SoundFileFormat

for wave_file in glob.glob('/home/yannick/*.wav'):
s = parselmouth.Sound(wave_file)
s_pre = s.pre_emphasize()
s.save(os.path.splitext(wave_file)[0] + '_pre.wav', SoundFileFormat.WAV)
s.save(os.path.splitext(wave_file)[0] + '_pre.aiff', SoundFileFormat.AIFF)
```

## Documentation
Though it is rather ugly and little for the moment, until more work will be done on this, the existing API documentation can be found [here](http://ai.vub.ac.be/~yajadoul/parselmouth.html).

## 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.

Briefly summarized, Parselmouth is built using [`cmake`](https://cmake.org/). Next to that, to manually build Parselmouth, the only requirement is a modern C++ compiler supporting the C++14 standard.

## Acknowledgements
- Parselmouth builds on the extensive code base of [Praat](https://github.com/praat/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](https://github.com/pybind/pybind11) library, allowing expose the C/C++ functionality of Praat as a Python interface.
- Special thanks go to [Bill Thompson](https://github.com/billdthompson) and [Robin Jadoul](https://github.com/RobinJadoul/) for their non-visible-in-history but very valuable contributions.

## License
Parselmouth is released under the GNU General Public License, version 3 or later. See [the `LICENSE` file](LICENSE) for details.

[Praat](https://github.com/praat/praat) is released under [the GNU General Public License, version 2 or later](praat/main/GNU_General_Public_License.txt). Small changes to this code base, made in the context of Parselmouth, can be found within the `git` history.

[pybind11](https://github.com/pybind/pybind11) is released under [a BSD-style license](pybind11/LICENSE).


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

praat-parselmouth-0.1.0.tar.gz (12.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

praat_parselmouth-0.1.0-cp36-cp36m-macosx_10_6_intel.whl (2.0 MB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

praat_parselmouth-0.1.0-cp35-cp35m-macosx_10_6_intel.whl (2.0 MB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

praat_parselmouth-0.1.0-cp34-cp34m-macosx_10_6_intel.whl (2.0 MB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

praat_parselmouth-0.1.0-cp27-cp27m-macosx_10_6_intel.whl (2.0 MB view details)

Uploaded CPython 2.7mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file praat-parselmouth-0.1.0.tar.gz.

File metadata

File hashes

Hashes for praat-parselmouth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7ed44c5ac66c29307f149bb5d7913050d9c70604d652bbca2f8923700036a5e
MD5 27ca444b016c5918865ffe1e298ef6d8
BLAKE2b-256 ea507ffe1a04842aa2cd2a600e054db2e4d53c6741ea4203ca6c3eddff0c59b0

See more details on using hashes here.

File details

Details for the file praat_parselmouth-0.1.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for praat_parselmouth-0.1.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 33f91095b3b040358135a25d915b2e1ce7b35685a004c81138bbfdb6f454671e
MD5 88018f046c0a5a0c1bb38cfdcda3127a
BLAKE2b-256 1d62c88a5edb76b5c3589b0d85dd221bafef35ec26998dce65bacb8f740be839

See more details on using hashes here.

File details

Details for the file praat_parselmouth-0.1.0-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for praat_parselmouth-0.1.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 9f5c26883acee2a9d3ab8cb130061330fc84c6e70e9a87c739c273bd4da4cd1b
MD5 626b10435b18bcd5c8f32f7df681da42
BLAKE2b-256 ffee06bf0fd03fde144fefc88338f8a0262eb5472a6178d46e95150f221927d0

See more details on using hashes here.

File details

Details for the file praat_parselmouth-0.1.0-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for praat_parselmouth-0.1.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 00069b033cc95f22815c6e23d5092e3abab348b34116e1f2ee199e40d09b4125
MD5 47e688e1a4d96f488219e6b9147a8b1d
BLAKE2b-256 1b5663d8892e1f9834e2a08624dfd421f261246ae120eb7e5b4b2f74a44537c4

See more details on using hashes here.

File details

Details for the file praat_parselmouth-0.1.0-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for praat_parselmouth-0.1.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5406ffd917043e06b897d1a53c89c4e4fa0d2dc3e52961479f5515c601b983bb
MD5 973ba9d34a2fb349a793d6fba5009979
BLAKE2b-256 100a594633341df49ade8c9029daa649df112885291c6ee226281e324984cb2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page