Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Query regarding finding Pitch at various levels: Parselmouth

71 views
Skip to first unread message

. PAL Anusuya

unread,
Jun 19, 2023, 8:22:38 AM6/19/23
to Parselmouth
Dear all,

Greetings of the day!

I am trying to extract the f0 at different time points (the total duration of the sound file is sliced into 10%). I have praat script, Scrip_Mel_Pitch_at_various_level_AG (attached), which works fine on the sound files (in a zipped folder attached). 

I have tried to write the code, first with one slice (attached as f0_timepoints.py); however, it gets a memory problem when I run it. I am not sure where I have made a mistake, but it looks like the line 
startpitch10 = call(pitch, 'Get value at time', vowelstart+(vowelend-vowelstart)*0.1, "Hertz", "Linear") 
in the code might not be correctly scripted. If I comment on this and related lines, I am able to process the data (attached as processed_results.csv). 

May I know what needs to be fixed? 

Any suggestion would really be helpful. 

Thanks,
Anu

f0_timepoints.py
audio.zip
processed_results.csv
Scrip_Mel_Pitch_at_various_level_AG

yannick...@gmail.com

unread,
Jun 20, 2023, 7:59:53 AM6/20/23
to Parselmouth
Dear Anu

If In understand correct, you're trying to directly translate the Praat script into a Python script, using Parselmouth, right?
Thank you for attaching all the relevant files. This really helps!

If so, one of the things missing from your Python version seems to be the TextGrid and the loop over all the vowel intervals in there:
```
        n = Get number of intervals... 1
        for i from 1 to n
```

So, currently, it seems you're only extracting one data point per audio file, rather than extracting one data point per vowel, as the other script.

I see two ways of going forward:
1) Continue what you're doing. Add the TextGrid reading and loop to the Python script. You can basically follow the same structure.
2) Just run the whole existing Praat script (that you already have) through `parselmouth.praat.run_file`; see https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.praat.run_file

It depends a bit on what you want to do. If you want to just run the whole analysis from Python, 2) might work, but of course you'll still need to have and maintain the Praat script.

I hope this helps. If no, don't hesitate to get back to me!
Kind regards
Yannick

. PAL Anusuya

unread,
Jun 25, 2023, 1:38:25 AM6/25/23
to Parselmouth
Dear Yannick,

Please accept my kind regards for answering my question. Thank you so much for your efforts.

I possibly didn't articulate my query quite clearly!

So, here is what I am looking forward to:

We recorded sound files in a particular set-up (for example, in a frame sentence of I X said,  where X is my target word with particular sound segments, in our case, different vowel segments, randomly occurring a few times).

Post-recording, we manually annotated the target vowels by labeling the start and the end positions and created TextGrids for tokens containing the target vowels. After that, we ran a script in Python to cut down only the portion that contained that vowel from the long sentences and saved them as independent vowel segments only. Therefore, we don't require separate TextGrids for these sound segments anymore. Now, what we have are just the sound files with the target vowels we were looking forward to! These sound files were attached as zipped audio files in my previous email. 

What we are particularly looking at is generating parameters, say f0, intensity, formant values, etc., of these small sound segments. We are definitely able to generate the mean values of these parameters (using Parselmouth); however, we want to generate values of these parameters over different time points. We want to calculate these parameters at every 10% or 20% of the total time points a particular sound segment contains. For example, if the sound token is 0.10ms, we should get values at 11 consecutive points (for every 10% of the time, the start point being T1 and the endpoint being T11). In this case, T1 should be calculated at 0.01ms, T3 at 0.02ms.. and so on!

We want to generate formant and pitch values for these tokens at different time points, basically using Python directly (not from the praat script). I showed the praat script to give an idea of what I exactly mean by time points. 

I hope I could make my query more clearer now. 

Please suggest to me how I should move forward from this point.

Thank you once again.
Anu

yannick...@gmail.com

unread,
Jun 26, 2023, 3:11:00 PM6/26/23
to Parselmouth
Dear Anu

Sorry, then I had misunderstood indeed.

What exactly is the problem then? The code using Parselmouth looks OK to me.
If I run it, the program does hang, at the very end. But that doesn't seem to have anything to do with Parselmouth. That's just because you append a list recursively to itself and NumPy has problems. If I add `print(startpitch10_list)` and Ctrl-C after a while, I get this:

```
$ python f0_timepoints.py
[[...], [...], [...], [...]]
^CTraceback (most recent call last):
  File "/home/yannick/TEMPORARY_PARSELMOUTH/f0_timepoints.py", line 57, in <module>
    df = pd.DataFrame(np.column_stack([file_list, duration_list, durationms_list, vowelstart_list, vowelend_list, mean_F0_list, startpitch10_list, sd_F0_list, hnr_list]),
  File "<__array_function__ internals>", line 200, in column_stack
  File "/home/yannick/.local/lib/python3.10/site-packages/numpy/lib/shape_base.py", line 652, in column_stack
    arr = asanyarray(v)
KeyboardInterrupt
```

So, the list recursively contains itself, and it happens during `np.column_stack(...)`, in NumPy. Nothing related to Parselmouth or how you use Parselmouth.

Kind regards
Yannick

anusuya pal

unread,
Jul 12, 2023, 2:58:45 AM7/12/23
to Parselmouth
Thanks, Yannick. The problem is solved! 
Anu

Reply all
Reply to author
Forward
0 new messages