Pitch Variation
The pitch variation metric checks whether your voice agent's pitch moves naturally within a reply, rather than sounding flat and robotic. If you set an upper limit, it also flags a voice that swings wildly up and down. It returns the share of agent replies whose pitch varies within range, between 0 and 1.
Required Arguments
To use the PitchVariationMetric, you'll have to provide a ConversationalTestCase with:
audioon the agent's turns, one clip per reply, or on the test case as a stereo recording of the whole call*
* Full call audio has to be stereo, with the caller and agent on separate channels, and is only used when no turn has audio. Each agent reply is then heard on the agent's channel, from its first sound until the caller speaks.
Usage
The PitchVariationMetric() can be used for end-to-end evaluation of voice calls, such as ones produced by the ConversationSimulator in voice mode:
from deepeval import evaluate
from deepeval.dataset import ConversationalGolden
from deepeval.metrics import PitchVariationMetric
from deepeval.simulator import ConversationSimulator
from deepeval.voice import ElevenLabsConnector, VoiceConfig
golden = ConversationalGolden(
scenario="The user asks the agent to look up an order by its number.",
expected_outcome="The agent reads back the order status.",
)
simulator = ConversationSimulator(
voice_config=VoiceConfig(
connector=ElevenLabsConnector(agent_id="your-agent-id"),
)
)
test_cases = simulator.simulate([golden])
metric = PitchVariationMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])There are FOUR optional parameters specific to the PitchVariationMetric, on top of the common voice metric parameters:
- [Optional]
min_spread_semitones: an integer for the least pitch spread, in semitones, a reply may have before it counts as monotone. Must be 0 or more. Defaulted to1. - [Optional]
max_spread_semitones: an integer for the most pitch spread, in semitones, a reply may have before it counts as erratic. Must be greater thanmin_spread_semitones. Defaulted toNone, which turns the erratic check off. - [Optional]
eval_mode:"deterministic"or"hybrid". In"hybrid", each flagged reply is double-checked by an audio decision model before it counts. Defaulted to the configured voice eval mode ("deterministic"unless set). - [Optional]
audio_decision_model: the model that does the second check in"hybrid"mode. Defaulted toHumeDecisionModel().
A value outside these limits raises a ValueError.
As a standalone
You can also run the PitchVariationMetric on a single test case as a standalone, one-off execution:
metric.measure(test_cases[0])
print(metric.score, metric.reason)
print(metric.score_breakdown)See Events for what score_breakdown contains.
Events
Each reply with too little or too much pitch movement shows up in score_breakdown. Here is what the example call returns:
{
"eligible_turns": 4,
"turns_with_events": 1,
"events": [
{
"type": "monotone",
"turn": 3,
"timing_source": "turn_timestamps",
"description": "Reply sounded monotone",
"pitch_spread_semitones": 0.0,
"offset_seconds": 0.0,
"duration_seconds": 5.0,
"start_time": 10.5,
"mark": "whole_reply",
}
],
"skipped": [
{
"turn": 9,
"error": "Reply has under 1s of voiced speech to follow its pitch.",
}
],
}| Field | What it means |
|---|---|
type | Monotone if the pitch barely moved, erratic if it swung too widely (only when max_spread_semitones is set) |
pitch_spread_semitones | How widely the reply's pitch moved, in semitones |
Each event covers the whole reply: offset_seconds is 0 and duration_seconds is the clip's length. Replies with under 1 second of voiced speech, or audio that can't be decoded, are listed under skipped.
Every event also has the fields all voice events share, such as mark and description.
eligible_turns is how many agent replies were counted and turns_with_events how many were flagged. The score is the share that weren't.
How Is It Calculated?
The PitchVariationMetric score is calculated according to the following equation:
The metric reads per-turn audio, one agent clip at a time, or replies cut from stereo full call audio when no turn has audio. The caller's turns are never checked.
Which replies are scored
The metric tracks the pitch of every 40 ms of the clip, between 70 and 500 Hz, and leaves out stretches that are near silent or have no clear pitch (such as "s" or "f" sounds). What's left is the voiced speech. A reply is scored if it has at least 1 second of it.
Pitch spread criteria
A reply's pitch spread is how far its 40 ms pitches typically sit from the reply's median pitch, in semitones. Because it uses a median, a single cracked word doesn't move it. Cracks are judged by Abrupt Pitch Jump instead.
| Check | Rule |
|---|---|
| Monotone | Spread under min_spread_semitones (1 by default), on a reply at least 4 seconds long |
| Erratic | Spread over max_spread_semitones, only when you set one |
A flat reply only sounds robotic once it runs a few seconds, so a shorter one is never flagged as monotone. It still counts towards the score.
If no agent reply has enough voiced speech, the metric is skipped.
Second check
In the hybrid eval mode, each flagged reply is double-checked before it counts. The audio decision model hears the agent's whole reply, from that turn's own clip, or from the reply cut from full call audio when no turn has audio, and is asked:
- Monotone: "Does the speaker sound flat and monotone, like a robot reading?"
- Erratic: "Does the speaker's pitch swing up and down erratically, in a way that sounds unnatural?"
If the model judges "no" more likely than "yes", the reply is dismissed and doesn't count against the score.
Example call
A call with five agent replies: one sounds natural, one is read flat for 5 seconds, one is as flat but only 3 seconds long, one swings widely, and one is too short to judge. Each row is one agent reply and its pitch spread.
| Agent turn | Length | Pitch spread | Flagged? |
|---|---|---|---|
| 1 | 5 s | 2.4 semitones | No |
| 3 | 5 s | 0.0 semitones | Yes (monotone) |
| 5 | 3 s | 0.0 semitones | No, under 4 seconds |
| 7 | 4 s | 8.9 semitones | No, no upper limit by default |
| 9 | 0.8 s | Under 1 s of voiced speech | Skipped |
| 4 replies | 1 flagged → 3/4 = 0.75 |
With max_spread_semitones=6, turn 7 is also flagged as erratic, and the score drops to 2/4 = 0.5.
FAQs
Why semitones rather than Hz?
Does this metric call an LLM or an external speech model?
"hybrid" eval mode, each flagged reply is also checked by an audio decision model, at one paid request per flagged reply.