speaker_helper.eardrum.expressive module
The prosody side of the Ralph Eardrum Loop: does the voice say it the way the text means it?
Module summary
Two readers of the same sentence, kept independent on purpose:
the text side says what the sentence calls for — the final contour its form implies (
intonation), and the arousal it expresses (calm, neutral, activated): from the narration’s ownemotiontag when the document gives one, otherwise from the local LLM reading the sentence;the audio side says what the voice did, from the signal alone, never a transcript (
prosody): the measured final contour, and the arousal shift against a neutral take of the same sentence by the same voice.
Arousal and contour are the two things the voice carries reliably. Valence (positive or negative) travels mostly through the words — Juslin & Laukka 2003; Wagner et al. 2023 found audio-only recognisers take it from implicit linguistic content — so it is reported from the text side and never judged from the audio.
The comparison is relative: a take is judged against a neutral take of the same sentence, because absolute emotion labels from recognisers trained on acted human speech collapse on synthetic speech (arXiv 2603.16483, 2026).
check_expression() measures; tune_expression() also tries the
engine’s levers in order until the take agrees, keeping the best.
Usage example
>>> expected_arousal_from_tag("angry"), expected_arousal_from_tag("sad")
('high', 'low')
- speaker_helper.eardrum.expressive.AROUSAL_STEP = 1.0
Arousal shift (in roughly semitone-sized units, see
arousal_shift()) a take must reach against its neutral reference to count as activated (high) or calmed (low). Measured on chatterbox (French, 2026-11-18): repeated neutral takes of one sentence differ by 0.15 to 1.4 from each other, a mean of about 0.6 — so a step of 1.0 against a reference averaged overREFERENCE_TAKEStakes is the smallest change that is not just another roll of the dice.
- speaker_helper.eardrum.expressive.DEFAULT_LEVERS: list[Callable[[dict[str, str], ExpectedContour, str], dict[str, str] | None]] = [<function retake>, <function retake>, <function marked_question>, <function closer_to_the_text>, <function stronger_emotion>, <function retake>]
new draws first (on a sampling engine the cheapest and most effective change), then the contour levers, then the emotion dial (inert on chatterbox French, see
stronger_emotion()), then one last draw with whatever dials stand.- Type:
The order the loop tries them in, measured rather than assumed
- class speaker_helper.eardrum.expressive.ExpressionResult(text, language, expected_contour, expected, neutral=<factory>, takes=<factory>, best=-1, verdict='unjudged')[source]
Bases:
objectEverything the prosody loop did for one sentence.
- Parameters:
- expected_contour
ExpectedContour, as a dict.- Type:
- expected
TextExpression, as a dict (None: no tag and no LLM).- Type:
dict or None
- neutral
The neutral take’s
ProsodyFeatures.- Type:
- takes
In the order tried.
- Type:
- verdict
ok(the first take agrees),fixed(a lever made it agree),unresolved, orunjudged(nothing to compare against).- Type:
- takes: list[ExpressionTake]
- class speaker_helper.eardrum.expressive.ExpressionTake(lever, say, emotion, intensity, pace, contour, contour_ok, arousal_shift, arousal_ok, audio='')[source]
Bases:
objectOne reading of a sentence with given dials, and what was measured.
- Parameters:
- emotion, intensity, pace
The dials.
- Type:
- speaker_helper.eardrum.expressive.Lever
given the segment’s dials, the dials of the next try (or
Nonewhen this lever does not apply). Tried in order until one agrees.- Type:
A lever
alias of
Callable[[dict[str,str],ExpectedContour,str], dict[str, str] | None]
- class speaker_helper.eardrum.expressive.ProsodyReport(results=<factory>, html=None, tuned=None, meta=<factory>)[source]
Bases:
objectWhat a prosody run produced.
- results
One per segment.
- Type:
- html
The report to listen to.
- Type:
Path or None
- tuned
The segments with the winning dials, ready for
narrate.- Type:
Path or None
- property agreement: dict[str, float | None]
Share of segments whose first take agreed, per dimension.
This is the answer to “does the voice say it the way the text means it?” before any tuning: contour over the segments where it could be measured and is not
either, arousal over all.
- results: list[ExpressionResult]
- speaker_helper.eardrum.expressive.REFERENCE_TAKES = 2
Neutral takes averaged into the reference (see
average_features()).
- speaker_helper.eardrum.expressive.TAG_AROUSAL: dict[str, str] = {'angry': 'high', 'calm': 'low', 'cautious': 'neutral', 'cheerful': 'high', 'contemplative': 'low', 'enthusiastic': 'high', 'friendly': 'neutral', 'neutral': 'neutral', 'sad': 'low', 'terrified': 'high', 'warm': 'neutral', 'whispering': 'low'}
The narration’s emotion tags (the chatterbox vocabulary) → the arousal each one means. Valence is deliberately absent: the voice does not carry it reliably, so the loop does not pretend to check it.
- class speaker_helper.eardrum.expressive.TakeSelector(max_draws=4, *, measure=None, reference_takes=2)[source]
Bases:
objectPick, for each narrated block, a draw that agrees with the text.
On a sampling engine the fix the prosody loop found is often a draw, not a dial: chatterbox said “Il est mort hier soir à l’hôpital.” too activated on its first take and calm on its third, with the same settings. Such a fix cannot be written into a segments file — the next narration draws again — so this chooser does it where the audio is made: passed as
Speaker.narrate(..., choose=TakeSelector(4)), it draws a block up tomax_drawstimes and keeps the first take that agrees, else the closest.What is judged, and what it costs:
the final contour, whenever the sentence’s form asks for one (a
., a yes/no question…) — free, no reference needed;the arousal, only for a block whose
emotiontag asks for calm or activation — it needs a neutral reference,REFERENCE_TAKESextra draws for that block.
A block with nothing to judge (a question that may rise or fall, no emotion) costs one draw, as without a chooser.
- Parameters:
- records
One per block:
index,text,draws,agrees,contour(expected, heard),arousal(expected, shift).
- class speaker_helper.eardrum.expressive.TextExpression(arousal, valence='neutral', emotion='neutral', source='tag')[source]
Bases:
objectWhat a sentence expresses, read from its words.
- emotion
The closest tag of
TAG_AROUSAL, so the engine’s emotion dial can be set from it.- Type:
- speaker_helper.eardrum.expressive.arousal_agrees(expected, shift, step=1.0)[source]
Whether a measured arousal shift matches what the text calls for.
- Parameters:
expected (str) –
"low","neutral"or"high".shift (float) –
arousal_shift()against the neutral take.step (float) – How far a take must move to count as activated or calmed.
- Returns:
highneedsshift ≥ step,lowneedsshift ≤ -step,neutralneeds|shift| < step.- Return type:
Examples
>>> arousal_agrees("high", 1.4), arousal_agrees("neutral", 1.4) (True, False)
- async speaker_helper.eardrum.expressive.check_expression(say, measure, segment, language, *, infer=<function infer_expression>, levers=None, save=None, reference_takes=2)[source]
Judge (and, with
levers, tune) how one sentence is said.- Parameters:
say (callable) –
async (dials) -> wav_bytes: synthesise the sentence with these dials (say,emotion,intensity) through the real engine.measure (callable) –
wav_bytes -> ProsodyFeatures(measure()).segment (dict) –
textand optionallysay,emotion,intensity.language (str) – Its language.
infer (callable or None) – Reads the expression from the words when the segment has no emotion tag (
infer_expression());Nonejudges the contour only.levers (list of Lever or None) – Changes to try, in order, while the take disagrees.
Noneonly measures.save (callable or None) –
(name, wav_bytes) -> relative pathto keep each take.reference_takes (int) – Neutral takes averaged into the reference.
- Returns:
Expectations, the neutral reference, every take and the verdict.
- Return type:
- speaker_helper.eardrum.expressive.closer_to_the_text(dials, contour, arousal)[source]
Read slower, which on chatterbox raises text guidance (
cfg_weight).Classifier-free guidance weighs the text against the voice prompt; more of it makes the reading follow the text — punctuation included — more closely. Applied only when the contour is wrong.
- Parameters:
dials (dict) – The current take’s dials.
contour (ExpectedContour) – The expected contour.
arousal (str) – The expected arousal (unused).
- Returns:
New dials with
paceslow, orNonewhen already slow or when the text accepts any contour.- Return type:
dict or None
- speaker_helper.eardrum.expressive.expected_arousal_from_tag(emotion)[source]
The arousal an emotion tag means, or
Nonefor an unknown tag.
- speaker_helper.eardrum.expressive.infer_expression(sentence, language)[source]
Ask the local LLM what emotion the words of
sentenceexpress.The model reads the text only. It answers in JSON with arousal, valence and the closest emotion tag; anything else is refused.
- Parameters:
- Returns:
Nonewhen the LLM stack is unavailable or the answer is malformed.- Return type:
TextExpression or None
- speaker_helper.eardrum.expressive.marked_question(dials, contour, arousal)[source]
Mark a rising question harder in what is said (never in what is shown).
Only for a sentence whose form calls for a rise: the final
?is doubled into?!, the spelling engines trained on web text associate with a strong rise. The page keeps its own punctuation — this changes the segment’ssay, not itstext.- Parameters:
dials (dict) – The current take’s dials.
contour (ExpectedContour) – The expected contour.
arousal (str) – The expected arousal (unused).
- Returns:
New dials, or
Nonewhen no rise is expected or already marked.- Return type:
dict or None
- speaker_helper.eardrum.expressive.parse_expression(answer)[source]
Validate the LLM’s JSON answer.
- Parameters:
answer (str) – Raw model output.
- Returns:
Noneunless every field is one of the allowed values.- Return type:
TextExpression or None
Examples
>>> parse_expression('{"arousal": "high", "valence": "negative", "emotion": "angry"}') TextExpression(arousal='high', valence='negative', emotion='angry', source='llm') >>> parse_expression('Sure! {"arousal": "very"}') is None True
- speaker_helper.eardrum.expressive.retake(dials, contour, arousal)[source]
Say it again with the same dials: a new roll of a stochastic engine.
The most effective lever measured on chatterbox (French): three takes of “Tu viens ce soir ?” with identical dials ended rise, level, rise. When the engine samples, asking again and keeping the take that agrees is a correction, not a trick — the dials did not change, only the draw.
- Parameters:
dials (dict) – The current take’s dials.
contour (ExpectedContour) – The expected contour (unused).
arousal (str) – The expected arousal (unused).
- Returns:
The same dials, marked as a new draw (the mark never reaches the engine).
- Return type:
- speaker_helper.eardrum.expressive.run_prosody(settings, segments, **kwargs)[source]
Synchronous wrapper around
run_prosody_async().- Parameters:
- Returns:
Results, agreement, report and tuned segments.
- Return type:
- async speaker_helper.eardrum.expressive.run_prosody_async(settings, segments, *, tune=True, infer=True, out_dir=None, speaker=None, measure=None, levers=None)[source]
Check (and tune) how every segment of a document is said.
- Parameters:
settings (Settings) – Engine and language.
segments (list of dict) –
textand optionallysay,emotion,intensity,pace(the narration format), or build them withsegments_from_text().tune (bool) – Try the levers on segments that disagree;
Falseonly measures the agreement between text and voice.infer (bool) – Let the local LLM read the expression of untagged segments.
out_dir (Path or None) – Report directory (a dated folder under
.private/eardrum-loop/).speaker (optional) – Injected collaborators (tests).
measure (optional) – Injected collaborators (tests).
levers (optional) – Injected collaborators (tests).
- Returns:
Results, agreement rates, report and tuned segments paths.
- Return type:
- speaker_helper.eardrum.expressive.segments_from_text(text)[source]
Cut a plain text into one segment per sentence.
Examples
>>> segments_from_text("Tu viens ? Oui. Super !") [{'text': 'Tu viens ?'}, {'text': 'Oui.'}, {'text': 'Super !'}]
- speaker_helper.eardrum.expressive.stronger_emotion(dials, contour, arousal)[source]
Push the emotion dial to the end of its range, towards the expected arousal.
Measured inert on chatterbox Multilingual (French, 2026-11-18):
exaggerationfrom 0.25 to 2.0 moved arousal by less than the take-to-take noise, as resemble-ai/chatterbox issue #355 reports; Turbo ignores the dial altogether. Kept, last, for the engines where it acts.- Parameters:
dials (dict) – The current take’s dials.
contour (ExpectedContour) – The expected contour (unused: this lever acts on arousal).
arousal (str) – The expected arousal.
- Returns:
New dials, or
Nonewhen arousal is neutral or the dial is already at its end.- Return type:
dict or None