Mark Esperida
Mark Esperida

Reputation: 109

Praat Integration in Python 2/3

I've been working on Praat for some audio analysis stuff. However, I found some libraries that use Praat in Python and would like to do the same.

This site offers a lot of features that can be extracted when praat is used. I have followed he instructions for "integrating" it in python. http://homepage.univie.ac.at/christian.herbst//python/index.html However, I couldn't get it to work. It returns the error:\ OSError: [Errno 2] No such file or directory

I also found another library: https://pypi.python.org/pypi/python-praat-scripts. This also returns the error (when I run the code below): OSError: [Errno 13] Permission denied

from praatinterface import PraatLoader
pl = PraatLoader(praatpath ='/Users/user/Downloads/praat6015_mac64.dmg')
text = pl.run_script('formants.praat', 'sample.wav', 5, 5500)
formants = pl.read_praat_out(text)

It would be great if someone can help me integrate praat to python properly. Thanks.

Upvotes: 1

Views: 2861

Answers (2)

Yannick Jadoul
Yannick Jadoul

Reputation: 401

[Disclaimer: I am the author of the mentioned Parselmouth library]

If you do not mind trying yet another library, Parselmouth integrates Praat into Python without the need for an external Praat binary:

import parselmouth
resulting_objects = parselmouth.praat.run_file('formants.praat', 'sample.wav', 5, 5500)

The resulting_objects variable will contain a list of the Praat objects that are selected, so if you make sure to select the Formant object, that will be returned. Alternatively, if you want to capture the output window, run

import parselmouth
output_string = parselmouth.praat.run_file('formants.praat', 'sample.wav', 5, 5500, capture_output=True)

Yet another alternative is to call the analysis from Python itself, and do something like this:

import parselmouth
sound = parselmouth.Sound("sample.wav")
formant = sound.to_formant_burg(max_number_of_formants=5, maximum_formant=5500)
formant.get_value_at_time(3, 0.5) # For the value of formant 3 at 0.5 seconds

Upvotes: 1

jja
jja

Reputation: 2098

I haven't used any of your tools, but it seems the problem might be with your praatpath variable. In the pages you link to, they are supposed to point to the Praat binary, whereas in your example you have them pointing to the Praat archive with the 64-bit Mac release.

You'll have to install Praat first. The instructions are pretty standard, but quoting from the Praat website:

After downloading, your web browser might open the .dmg file directly; you will then see the program Praat or Praat.app. If your browser did not open the .dmg file, then you should double-click the .dmg file in the Downloads window (or in the Downloads folder in your home directory); after double-clicking you may see the program Praat or Praat.app directly, or you may see a disk icon called Praat6016, which when you open it will show you the program Praat or Praat.app. To install Praat, just drag the program Praat or Praat.app to your Applications folder (or anywhere else).

Once that is done, the praatpath variable should point to this executable.

This applies to your second example, but I suspect that the problem might be similar for the first (ie. it doesn't know where Praat is, because it is either not installed or not in PATH).

Upvotes: 0

Related Questions