python2/3中的Praat集成

2024-09-27 09:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在用Praat做音频分析。但是,我发现一些库在Python中使用Praat,并且希望这样做。在

这个网站提供了很多可以在使用praat时提取的功能。我遵循了在python中“集成”它的说明。http://homepage.univie.ac.at/christian.herbst//python/index.html 但是,我不能让它工作。它返回错误:\ OSError:[Errno 2]没有这样的文件或目录

我还发现了另一个库:https://pypi.python.org/pypi/python-praat-scripts。这也会返回错误(当我运行下面的代码时):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)

如果有人能帮助我将praat正确地集成到python中,那就太好了。谢谢。在


Tags: text功能pypihttp网站错误音频pl
2条回答

我没有使用过您的任何工具,但问题可能出在您的praatpath变量上。在您链接到的页面中,它们应该指向Praat二进制文件,而在您的示例中,它们指向的是64位Mac版本的Praat归档文件。在

你必须先安装Praat。说明书相当标准,但引自Praat网站:

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

完成后,praatpath变量应该指向这个可执行文件。在

这适用于您的第二个示例,但我怀疑第一个示例的问题可能类似(即它不知道Praat在哪里,因为它要么没有安装,要么没有在PATH中安装)。在

[免责声明:我是上述Parselmouth库的作者]

如果您不介意尝试另一个库,Parselmouth将Praat集成到Python中,而不需要外部Praat二进制文件:

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

resulting_objects变量将包含所选Praat对象的列表,因此如果您确保选择Formant对象,则将返回该对象。或者,如果要捕获输出窗口,请运行

^{pr2}$

另一种选择是从Python本身调用分析,然后执行如下操作:

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

相关问题 更多 >

    热门问题