Compute formants

860 views
Skip to first unread message

Dayana Ribas

unread,
Apr 21, 2021, 9:17:46 AM4/21/21
to Parselmouth
Dear Yannick, 
I'm trying to use parselmouth for computing pitch and formants. For pitch, great, as usually praat does. But for formants, I'm obtaining just a few values, a then nan. I'm also surprised that formants values are not sincronized with the pitch result. I mean, that for pitch=0, formants should also be 0. Anyway, I submit my code to your considerations, just in case you can bring me some light over this issue. 


Best regards
Dayana


yannick...@gmail.com

unread,
Apr 21, 2021, 10:41:53 AM4/21/21
to Parselmouth
Hi Dayana

OK, I think I figured out what's going wrong. You are using the `t` frame index (going from 0 to `frames`) as a time (passing it to "Get value at time"). So those are interpreted by Praat (and thus Parselmouth as well) as time in seconds.

One easy way of fixing it would be to have `for t in formants.ts():` (and get rid of the `t += 1`). Another way would be to convert the index to the time (e.g. with https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.TimeFrameSampled.frame_number_to_time; but watch out, Praat frame numbers is 1-based, while Python is 0-based!).

Apart from that, I have a few more suggestions to make things easier to read: rather than writing `formants = call(sound, "To Formant (burg)", 0.010, 5, 5000, 0.025, 50)`, you could also write `sound.to_formant_burg(time_step=0.010, maximum_formant=5000)`, as it allows you to skip the default values. See https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.Sound.to_formant_burg
The same goes for using `formants.get_value_at_time(1, t)`, for example: https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.Formant.get_value_at_time

I hope this helps? If not, or you encounter further issues, please don't hesitate to get back to me!

Kind regards
Yannick

Dayana Ribas

unread,
Apr 21, 2021, 5:14:50 PM4/21/21
to Parselmouth
Many thanks!! 
It's working fine now. Maybe in the future you could add something like the "pitch.selected_array['frequency']" also to formants to easier this process. 
I proofreaded the example in github (same link), so If you find it useful to add it to the five examples available in the documentation, please don't hesitate. Could be useful for someone interested in compute formants with parselmouth and a way to contribute to the hard task of documentation ;). 

Best regards
Dayana

Cedric Biedermann

unread,
Jun 23, 2021, 7:07:12 AM6/23/21
to Parselmouth

Hello,

if i trie to rerun this code i get the error:
To analyse this Sound, “minimum pitch” must not be less than 66150 Hz.
Does somebody know how to fix that?
Thank your very much
Regards Cedric

yannick...@gmail.com

unread,
Jun 23, 2021, 7:21:57 AM6/23/21
to Parselmouth
Hi Cedric

What exact code do you run? Could it be that your audio file is too short to analyse the pitch?
Have you looked up the error? It seems there's a bunch of answers on what this Praat error means: e.g., https://stackoverflow.com/questions/56484883/praat-error-when-processing-pitch-of-wav-file-minimum-pitch-must-not-be-les

Also, please start a new thread (in which you can refer to old thread), rather than adding new messages to already resolved issues, please. Thank you.

Yannick
Reply all
Reply to author
Forward
0 new messages