speaker_helper.eardrum.prosody module
Prosody: what the voice did, measured from the audio alone.
Module summary
The pronunciation loop asks which sounds were said; the prosody loop asks how they were said — the melody at the end of the sentence (did a question rise?) and the energy of the delivery (calm or excited?). Both are read from the signal, never from a transcript, so the words cannot vouch for a reading the voice did not give.
pitch_track()— the fundamental frequency (F0) over time, by pYIN.final_contour()— the movement of the last voiced stretch, in semitones, and its shape:rise,fallorlevel.measure()— every feature of one take in aProsodyFeatures: median F0, F0 range, final contour, loudness and its spread, voiced share.arousal_shift()— how much more (or less) activated a take is than a neutral take of the same sentence by the same voice. Arousal is relative by nature: a high voice is not an excited one, and comparing a take with its own neutral reading cancels the speaker.
Semitones, not hertz: a rise of 30 Hz is large for a low voice and small for a high one, while 2 semitones is the same perceived step for both.
Usage example
>>> semitones(220.0, 110.0)
12.0
- speaker_helper.eardrum.prosody.CREAK_S = 0.04
the voice often creaks or drops into vocal fry there, which the tracker reads as a fall.
- Type:
The last voiced 40 ms are left out of the final contour
- class speaker_helper.eardrum.prosody.Contour(slope_st, rise_st, fall_st, shape)[source]
Bases:
objectThe melody of the end of an utterance.
- speaker_helper.eardrum.prosody.F0_MIN_HZ = 65.0
pYIN search range. 65 Hz covers a low male voice; 600 Hz an excited female one (the default voices here are female, ~180-250 Hz at rest).
- speaker_helper.eardrum.prosody.FINAL_WINDOW_S = 0.4
How much of the end of the utterance the final contour looks at.
- speaker_helper.eardrum.prosody.HOP = 160
10 ms, the usual resolution for intonation.
- Type:
Analysis hop
- class speaker_helper.eardrum.prosody.ProsodyFeatures(f0_median_hz, f0_range_st, final, loudness_db, loudness_spread_db, voiced_share, duration_s)[source]
Bases:
objectWhat one take’s voice did.
- Parameters:
- final
Final contour (see
final_contour()).- Type:
Contour or None
Share of frames that are voiced (a proxy for pausing and rate).
- Type:
- speaker_helper.eardrum.prosody.RISE_ST = 3.0
Contour thresholds, in semitones over the final window. Perception needs roughly 1.5-3 st of excursion (‘t Hart 1981); these are the engineering values the TTS-prosody literature uses (no standard exists): a rise must climb at least 3 st above the window’s low point, a fall end at least 2 st below its high point.
- speaker_helper.eardrum.prosody.SAMPLE_RATE = 16000
pYIN is accurate and cheap at 16 kHz for speech.
- Type:
Analysis rate
- speaker_helper.eardrum.prosody.arousal_shift(take, neutral)[source]
How much more activated
takeis thanneutral, in one number.The classic acoustic correlates of arousal, each relative to the neutral reading of the same sentence by the same voice: higher median F0 (in semitones), wider F0 range (semitones), louder (dB, at a third of the weight: loudness is partly the engine’s normalisation, not the voice). Positive is more activated, negative calmer, around 0 the same.
- Parameters:
take (ProsodyFeatures) – The take under judgement.
neutral (ProsodyFeatures) – A neutral take of the same text by the same voice.
- Returns:
The shift, in roughly semitone-sized units.
- Return type:
Examples
>>> base = ProsodyFeatures(200.0, 6.0, None, -20.0, 12.0, 0.6, 2.0) >>> excited = ProsodyFeatures(238.0, 9.0, None, -17.0, 14.0, 0.6, 1.8) >>> round(arousal_shift(excited, base), 2) # +3.0 st, +3.0 st, +3 dB / 3 2.34
- speaker_helper.eardrum.prosody.average_features(takes)[source]
One reference out of several takes of the same reading.
Measured on chatterbox (French): three takes of the same sentence with the same dials differ by up to 1.4 in
arousal_shift()— as much as a real change of emotion. A single neutral take is therefore a noisy reference; averaging several makes it steadier. Pitch is averaged in the log domain (a geometric mean), the rest arithmetically; the final contour is not averaged (it is judged per take).- Parameters:
takes (list of ProsodyFeatures) – At least one.
- Returns:
The averaged reference (
finalisNone).- Return type:
Examples
>>> a = ProsodyFeatures(200.0, 6.0, None, -20.0, 10.0, 0.6, 2.0) >>> b = ProsodyFeatures(800.0, 8.0, None, -24.0, 12.0, 0.4, 3.0) >>> average_features([a, b]).f0_median_hz 400.0
- speaker_helper.eardrum.prosody.final_contour(times, f0, window_s=0.4)[source]
How the melody moves over the last voiced stretch.
The window is the last
window_sseconds of voicing, minus the finalCREAK_S. Its F0 is put in semitones from the utterance median; the slope is a Theil-Sen fit (the median of pairwise slopes, so one stray frame cannot flip it), and the excursions are measured from the window’s extremes to its last frames.- Parameters:
times (numpy.ndarray) – Frame times (s).
f0 (numpy.ndarray) – F0 in Hz,
nanwhere unvoiced.window_s (float) – Length of the final stretch examined.
- Returns:
The contour, or
Nonewith fewer than five voiced frames in the window.- Return type:
Contour or None
Examples
>>> import numpy as np >>> t = np.arange(0, 1, 0.01) >>> rising = 200 * 2 ** (np.clip(t - 0.6, 0, None) * 10 / 12) # +4 st at the end >>> final_contour(t, rising).shape 'rise'
- speaker_helper.eardrum.prosody.measure(wav_bytes)[source]
Measure one take’s prosody.
- Parameters:
wav_bytes (bytes) – Encoded audio of the take.
- Returns:
Its features (F0 fields
Nonewhen the take has almost no voicing).- Return type:
- speaker_helper.eardrum.prosody.pitch_track(samples)[source]
F0 over time by probabilistic YIN, cleaned for intonation work.
Voicing is pYIN’s own HMM decision, not a threshold on its per-frame probability: the 0.5 cut the literature suggests kept 24 of 89 voiced frames on a kokoro sentence, which leaves no final contour to measure. The track is then median-filtered over five frames (50 ms), and any frame more than an octave from the utterance median is dropped as an octave error of the tracker.
- Parameters:
samples (numpy.ndarray) – Mono audio at
SAMPLE_RATE.- Returns:
Frame times in seconds, and F0 in Hz (
nanwhere unvoiced).- Return type:
tuple of (numpy.ndarray, numpy.ndarray)