Giter Site home page Giter Site logo

seanpue / parselmouth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yannickjadoul/parselmouth

0.0 2.0 0.0 16.26 MB

Praat in Python, the Pythonic way

License: GNU General Public License v3.0

CMake 0.40% C++ 79.63% C 17.99% Makefile 0.15% Objective-C 0.36% Python 1.45% Shell 0.02%

parselmouth's Introduction

Parselmouth - Praat in Python, the Pythonic way

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.

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, 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):

import pip
pip.main(['install', 'praat-parselmouth'])
  • On Mac OS X, this should be fairly quickly.
  • On a Linux system, we do not have a binary distribution yet, but pip install praat-parselmouth should automatically build your project in 5 to 10 minutes if you have cmake installed.
  • Unfortunately, at this point in time, we do not have a Windows version available to download from the Python Package Index. Work will be done on this, and even sooner if we get feedback from interested potential Windows users ;-)

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, log a GitHub issue, or write me a quick email. We are of course very grateful for you feedback!

Example usage

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

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

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

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

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

Parselmouth is released under the GNU General Public License, version 3 or later. See the LICENSE file for details.

Praat is released under the GNU General Public License, version 2 or later. Small changes to this code base, made in the context of Parselmouth, can be found within the git history.

pybind11 is released under a BSD-style license.

parselmouth's People

Contributors

yannickjadoul avatar

Watchers

James Cloos avatar A. Sean Pue avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.