1

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.

Mark Esperida
  • 109
  • 1
  • 8

2 Answers2

1

[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
Yannick Jadoul
  • 391
  • 1
  • 11
  • 1
    Hello Yannick, i use this : `objects = parselmouth.praat.run_file('crosscorelate.praat', wav_filename1, wav_filename2, capture_output=True)` but i get the error `parselmouth.PraatError: Found 2 arguments but expected more. Script not completed.` even though it's working with the binary executable : `Praat.exe crosscorelate.praat one.wav two/wav` what am i doing wrong ? – Narthe Aug 31 '18 at 21:51
  • Hello Narthe. It's hard to see from this one line (without the script). The error comes from somewhere inside Praat, but the error might be in my code linking Python to Praat. I'd be very happy to look into this and solve it, though! Could you somehow get me some more information or the script? If easier, you could open an issue on GitHub (https://github.com/YannickJadoul/Parselmouth/issues), or talk further on Gitter (https://gitter.im/PraatParselmouth/Lobby) – Yannick Jadoul Sep 01 '18 at 08:17
  • @Narthe I think I understand the problem. Parselmouth checks the amount of parameters to your script, while Praat does not and leave them undefined or empty if you do not give enough parameters. The solution is to either pass the extra parameters needed to the Praat script (see the 'form' construct in the script), or to remove unnecessary parameters from the 'form' in the script. – Yannick Jadoul Sep 02 '18 at 14:08
  • Thanks for the answer Yannick ! It was really dumb of me, i didn't check the praat script and it has 2 additionnal parameters with a default value, so that's why it was working with the executable. – Narthe Sep 04 '18 at 14:01
  • @Narthe Good to hear it works! :-) It's not really you, though: Praat will not check the number of arguments from the command line, and as far as I tested, it will also not insert the default parameters. (If you're using the same `'crosscorelate.praat'` that I found online, the two last parameters are not used, and that's why their `undefined` value does not cause any trouble.) – Yannick Jadoul Sep 04 '18 at 15:18
0

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

jja
  • 2,058
  • 14
  • 27
  • I've installed praat but the praatath command still returns the same error. – Mark Esperida Apr 18 '16 at 08:24
  • The `praatpath` _command_? You mean the option on your script? What path did you set it to? – jja Apr 18 '16 at 15:46
  • i set it to the praat directory or where the praat program is located – Mark Esperida Jul 07 '16 at 11:45
  • It should point to the Praat binary, not its directory. See if that works. – jja Jul 07 '16 at 17:26
  • how do you locate the praat binary? – Mark Esperida Jul 08 '16 at 07:37
  • The binary is the executable. When you run Praat, you need to execute that file. So, if you say "the praat program is located" in, say `/home/user/bin`, and that's the directory, then the path to the executable would be something like `/home/user/bin/praat`. – jja Jul 08 '16 at 08:17