From 206f148114ad8f86a61a9c8ad77a0fa64e949106 Mon Sep 17 00:00:00 2001 From: Takeshi Ikuma Date: Mon, 22 Feb 2021 14:39:46 -0600 Subject: [PATCH] Added another Pitch method: - get_fraction_of_locally_unvoiced_frames() --- src/parselmouth/Pitch.cpp | 12 ++++++++++++ src/parselmouth/Pitch_docstrings.h | 28 ++++++++++++++++++++++++++++ tests/test_pitch.py | 2 ++ 3 files changed, 42 insertions(+) diff --git a/src/parselmouth/Pitch.cpp b/src/parselmouth/Pitch.cpp index 374c850c..93daeab0 100644 --- a/src/parselmouth/Pitch.cpp +++ b/src/parselmouth/Pitch.cpp @@ -410,6 +410,18 @@ PRAAT_CLASS_BINDING(Pitch) { "get_maximum", &Pitch_getMaximum, "from_time"_a = 0.0, "to_time"_a = 0.0, "unit"_a = "HERTZ", "interpolate"_a = true, GET_MAXIMUM_DOCSTRING); + def( + "get_fraction_of_locally_unvoiced_frames", + [](Pitch self, double tmin, double tmax, double ceiling, + double silenceThreshold, double voicingThreshold) { + MelderFraction out = Pitch_getFractionOfLocallyUnvoicedFrames(self, tmin, tmax, ceiling, + silenceThreshold, voicingThreshold); + + return std::make_tuple(out.numerator / out.denominator, out.numerator, out.denominator); + }, + "from_time"_a = 0.0, "to_time"_a = 0.0, "to_pitch"_a = 600.0, "silence_threshold"_a = 0.03, + "voicing_threshold"_a = 0.45, GET_FRACTION_OF_LOCALLY_UNVOICED_FRAMES_DOCSTRING); + // End added by @hokiedsp on 2/17/21 // TODO Pitch_Intensity_getMean & Pitch_Intensity_getMeanAbsoluteSlope ? (cfr. Intensity) diff --git a/src/parselmouth/Pitch_docstrings.h b/src/parselmouth/Pitch_docstrings.h index 605355bb..70ec4af1 100644 --- a/src/parselmouth/Pitch_docstrings.h +++ b/src/parselmouth/Pitch_docstrings.h @@ -156,4 +156,32 @@ See Also :praat:`Voice report` )"; +constexpr auto GET_FRACTION_OF_LOCALLY_UNVOICED_FRAMES_DOCSTRING = R"(Get unvoiced statistics + +Returns the statistics related to the unvoiced periods + +Parameters +---------- +from_time : double=0.0 + The starting time of the analysis time domain. + +to_time : double=0.0 + The ending time of the analysis time domain. Values outside this domain + are ignored. If `to_time` is not greater than `from_time`, the entire + time domain of the Pitch object is considered. + +to_pitch : double=600.0 + The maximum voice frequency + +silence_threshold : double=0.03 + The upper pitch strength limit of silent period + +voicing_threshold : double 0.45 + The lower pitch strength limit of voicing period + +See Also +-------- +:praat:`Voice report` +)"; + }// namespace parselmouth \ No newline at end of file diff --git a/tests/test_pitch.py b/tests/test_pitch.py index 4ad5d2fd..000da613 100644 --- a/tests/test_pitch.py +++ b/tests/test_pitch.py @@ -21,3 +21,5 @@ def test_get_maximum(pitch): def test_get_quantile(pitch): print(f"10% Quantile={pitch.get_quantile(0.1)}") +def test_get_fraction_of_locally_unvoiced_frames(pitch): + print(pitch.get_fraction_of_locally_unvoiced_frames()) \ No newline at end of file