Parselmouth icon indicating copy to clipboard operation
Parselmouth copied to clipboard

Example for cross_correlate function

Open olivierfriard opened this issue 6 years ago • 4 comments

Hello,

I am doing some tests to migrate from praat script to parselmouth. May you give some example for using the croos_correlate function?

My praat script is (part of):

             Read from file... 'directory$'/'sound1$'
             Rename... 1

             Read from file... 'directory$'/'sound2$'
             Rename... 2

             select Sound 1
             plus Sound 2

             Cross-correlate... -0.20 0.20 yes
             ccvalue = Get maximum... 0 0 Sinc70

I wrote this in Python:

import parselmouth as pm
s1 = pm.Sound("sound1.wav")
s2 = pm.Sound("sound2.wav")
cc = s1.cross_correlate(s2)

Everything is going well but I do not know how to extract the cc value... Thank you Olivier

olivierfriard avatar May 29 '18 14:05 olivierfriard

Unfortunately, I don't think that "Get maximum" function has been ported to the Python API yet. As far as I remember, there were some problems/design issues with units and/or interpolation to add this to the Sampled base class. But I should probably have a look at porting this in a future version.

However, until this issue can get solved, I would suggest using parselmouth.praat.call(cc, "Get maximum", 0, 0, "Sinc70"), which shóuld work and give you the same answer?

YannickJadoul avatar May 29 '18 16:05 YannickJadoul

(I would advise against the other option, i.e. cc.values.max(), because this will only get you the maximum sample without interpolating, so this would be like choosing None as interpolation)

YannickJadoul avatar May 29 '18 16:05 YannickJadoul

Hi,

thank you. I will make some tests.

On Tue, May 29, 2018 at 6:53 PM, Yannick Jadoul [email protected] wrote:

(I would advise against the other option, i.e. cc.values.max(), because this will only get you the maximum sample without interpolating, so this would be like choosing None as interpolation)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YannickJadoul/Parselmouth/issues/4#issuecomment-392850954, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOgYmnYvFHPEAxe6o6jWbDqOz6f4NE7ks5t3X0UgaJpZM4URp6E .

-- University of Torino Life Sciences and Systems Biology department Via dell'Accademia Albertina, 13 10123 TORINO (Italy) tel: +39 011 6704542 http://www.di.unito.it/~friard/ http://orcid.org/0000-0002-0374-9872

olivierfriard avatar May 30 '18 07:05 olivierfriard

Thanks; do let me know when it doesn't work as intended. By the way: I still need to put an example together and add it to ReadTheDocs, but if you have larger existing Praat scripts, you can also use parselmouth.praat.run and parselmouth.praat.run_file

YannickJadoul avatar May 30 '18 09:05 YannickJadoul