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 own emotion tag 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')

Author

Warith HARCHAOUI — https://linkedin.com/in/warith-harchaoui

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 over REFERENCE_TAKES takes 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: object

Everything the prosody loop did for one sentence.

Parameters:
text

The sentence as the page shows it.

Type:

str

language

Its language.

Type:

str

expected_contour

ExpectedContour, as a dict.

Type:

dict

expected

TextExpression, as a dict (None: no tag and no LLM).

Type:

dict or None

neutral

The neutral take’s ProsodyFeatures.

Type:

dict

takes

In the order tried.

Type:

list of ExpressionTake

best

Index of the best take.

Type:

int

verdict

ok (the first take agrees), fixed (a lever made it agree), unresolved, or unjudged (nothing to compare against).

Type:

str

best: int = -1
expected: dict[str, Any] | None
expected_contour: dict[str, Any]
language: str
neutral: dict[str, Any]
takes: list[ExpressionTake]
text: str
verdict: str = 'unjudged'
class speaker_helper.eardrum.expressive.ExpressionTake(lever, say, emotion, intensity, pace, contour, contour_ok, arousal_shift, arousal_ok, audio='')[source]

Bases: object

One reading of a sentence with given dials, and what was measured.

Parameters:
lever

What was changed for this take ("as written", "intensity 0.9"…).

Type:

str

say

The text the engine was handed.

Type:

str

emotion, intensity, pace

The dials.

Type:

str

contour

Measured final contour shape.

Type:

str or None

contour_ok

Agreement with the expected contour (None: not measurable).

Type:

bool or None

arousal_shift

Against the neutral take.

Type:

float

arousal_ok

Agreement with the expected arousal.

Type:

bool

audio

Path of the take, relative to the report directory.

Type:

str

property agrees: bool

Contour and arousal both agree (an unmeasurable contour does not block).

arousal_ok: bool
arousal_shift: float
audio: str = ''
contour: str | None
contour_ok: bool | None
emotion: str
intensity: str
lever: str
pace: str
say: str
speaker_helper.eardrum.expressive.Lever

given the segment’s dials, the dials of the next try (or None when 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: object

What a prosody run produced.

Parameters:
results

One per segment.

Type:

list of ExpressionResult

html

The report to listen to.

Type:

Path or None

tuned

The segments with the winning dials, ready for narrate.

Type:

Path or None

meta

Engine, language, date, whether it tuned.

Type:

dict

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.

html: Any = None
meta: dict[str, Any]
results: list[ExpressionResult]
tuned: Any = None
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: object

Pick, 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 to max_draws times 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 emotion tag asks for calm or activation — it needs a neutral reference, REFERENCE_TAKES extra 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:
  • max_draws (int) – Most draws per block (at least 1).

  • measure (callable or None) – wav_bytes -> ProsodyFeatures; measure() by default.

  • reference_takes (int) – Neutral draws averaged into the arousal reference.

records

One per block: index, text, draws, agrees, contour (expected, heard), arousal (expected, shift).

Type:

list of dict

records: list[dict[str, Any]]
class speaker_helper.eardrum.expressive.TextExpression(arousal, valence='neutral', emotion='neutral', source='tag')[source]

Bases: object

What a sentence expresses, read from its words.

Parameters:
arousal

"low", "neutral" or "high".

Type:

str

valence

"negative", "neutral" or "positive" — reported, never judged against the audio.

Type:

str

emotion

The closest tag of TAG_AROUSAL, so the engine’s emotion dial can be set from it.

Type:

str

source

"tag" (the document said so) or "llm".

Type:

str

arousal: str
emotion: str = 'neutral'
source: str = 'tag'
valence: str = 'neutral'
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:

high needs shift ≥ step, low needs shift ≤ -step, neutral needs |shift| < step.

Return type:

bool

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) – text and optionally say, 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()); None judges the contour only.

  • levers (list of Lever or None) – Changes to try, in order, while the take disagrees. None only measures.

  • save (callable or None) – (name, wav_bytes) -> relative path to keep each take.

  • reference_takes (int) – Neutral takes averaged into the reference.

Returns:

Expectations, the neutral reference, every take and the verdict.

Return type:

ExpressionResult

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 pace slow, or None when 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 None for an unknown tag.

Parameters:

emotion (str) – A narration emotion value.

Returns:

"low", "neutral" or "high".

Return type:

str or None

speaker_helper.eardrum.expressive.infer_expression(sentence, language)[source]

Ask the local LLM what emotion the words of sentence express.

The model reads the text only. It answers in JSON with arousal, valence and the closest emotion tag; anything else is refused.

Parameters:
  • sentence (str) – The sentence.

  • language (str) – Its language (for the prompt).

Returns:

None when 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’s say, not its text.

Parameters:
  • dials (dict) – The current take’s dials.

  • contour (ExpectedContour) – The expected contour.

  • arousal (str) – The expected arousal (unused).

Returns:

New dials, or None when 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:

None unless 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:

dict

speaker_helper.eardrum.expressive.run_prosody(settings, segments, **kwargs)[source]

Synchronous wrapper around run_prosody_async().

Parameters:
  • settings (Settings) – Engine and language.

  • segments (list of dict) – The narration segments.

  • **kwargs – Forwarded unchanged.

Returns:

Results, agreement, report and tuned segments.

Return type:

ProsodyReport

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) – text and optionally say, emotion, intensity, pace (the narration format), or build them with segments_from_text().

  • tune (bool) – Try the levers on segments that disagree; False only 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:

ProsodyReport

speaker_helper.eardrum.expressive.segments_from_text(text)[source]

Cut a plain text into one segment per sentence.

Parameters:

text (str) – The document.

Returns:

{"text": sentence} each.

Return type:

list of dict

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): exaggeration from 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 None when arousal is neutral or the dial is already at its end.

Return type:

dict or None