Pitch Consistency
The pitch consistency metric checks whether your voice agent keeps the same voice from one reply to the next, rather than sounding clearly deeper or higher in one of them. It returns the share of agent replies that stay close to the agent's typical pitch, between 0 and 1.
Required Arguments
To use the PitchConsistencyMetric, you'll have to provide a ConversationalTestCase with:
audioon the agent's turns, one clip per reply, for at least 3 replies, 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 PitchConsistencyMetric() 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 PitchConsistencyMetric
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 = PitchConsistencyMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])There is ONE optional parameter specific to the PitchConsistencyMetric, on top of the common voice metric parameters:
- [Optional]
max_shift_semitones: an integer for how far, in semitones, a reply's pitch may sit from the agent's typical pitch. Must be greater than 0, or aValueErroris raised. Defaulted to3.
As a standalone
You can also run the PitchConsistencyMetric 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 whose pitch drifted too far shows up in score_breakdown. Here is what the example call returns:
{
"eligible_turns": 5,
"turns_with_events": 2,
"events": [
{
"type": "pitch_shift",
"turn": 3,
"timing_source": "turn_timestamps",
"description": "Voice sat 4 semitones lower than in the agent's other replies",
"pitch_base_hz": 161.8,
"shift_semitones": -3.8,
"offset_seconds": 0.0,
"duration_seconds": 7.0,
"start_time": 12.5,
"mark": "whole_reply",
},
{
"type": "pitch_shift",
"turn": 7,
"timing_source": "turn_timestamps",
"description": "Voice sat 4 semitones higher than in the agent's other replies",
"pitch_base_hz": 257.0,
"shift_semitones": 4.1,
"offset_seconds": 0.0,
"duration_seconds": 7.0,
"start_time": 32.5,
"mark": "whole_reply",
},
],
"skipped": [
{
"turn": 11,
"error": "Reply has under 3s of voiced speech to follow its pitch.",
}
],
}| Field | What it means |
|---|---|
pitch_base_hz | The reply's base pitch, in Hz |
shift_semitones | How far that sits from the agent's typical pitch, in semitones. Negative when deeper |
Each event covers the whole reply: offset_seconds is 0 and duration_seconds is the clip's length. The description rounds the shift to a whole number. Replies with under 3 seconds 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 compared and turns_with_events how many drifted. The score is the share that didn't.
How Is It Calculated?
The PitchConsistencyMetric 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 3 seconds of it, since that is how long a voice's base pitch takes to settle.
It takes at least 3 scored replies to tell which one is off. With fewer, the metric is skipped.
Pitch shift criteria
Each reply is judged on its base pitch: the low end its voice keeps returning to between the words it stresses. It moves far less from reply to reply than the middle of the voice, so a stressed word or a question doesn't make a reply look off.
| Check | Rule |
|---|---|
| Base pitch | The 10th percentile of the reply's 40 ms pitches |
| Check reading | The 20th percentile, read the same way, since a few creaky frames can drag the very lowest pitch down on their own |
| Typical pitch | The median base pitch across all counted replies, so one odd reply is flagged on its own instead of pulling the typical pitch towards it |
| Shift | How far the reply sits from the typical pitch, by both readings. Only the part they agree on counts: 0 if they point in opposite directions, otherwise the smaller of the two |
| Pitch shift | A shift of more than max_shift_semitones (3 by default) above or below |
Example call
A call with six agent replies, all 7 seconds long except the last: most have a base pitch near 200 Hz, one is clearly deeper, one clearly higher, and the last is too short to judge. Each row is one agent reply, its base pitch and how far that is from the typical 201.9 Hz.
| Agent turn | Base pitch | Shift | Flagged? |
|---|---|---|---|
| 1 | 201.9 Hz | 0 semitones | No |
| 3 | 161.8 Hz | −3.8 semitones | Yes |
| 5 | 209.9 Hz | +0.7 semitones | No |
| 7 | 257.0 Hz | +4.1 semitones | Yes |
| 9 | 197.0 Hz | −0.4 semitones | No |
| 11 | Under 3 s of voiced speech | Skipped | |
| 5 replies | 2 flagged → 3/5 = 0.6 |