Volume Variance
The volume variance metric checks whether your voice agent's volume drifts within a reply, like a sentence that starts loud and fades to a mumble, or one that swells as it goes. It returns the share of agent replies that hold a steady volume, between 0 and 1.
Required Arguments
To use the VolumeVarianceMetric, you'll have to provide a ConversationalTestCase with audio on the agent's turns, 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 VolumeVarianceMetric() 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 VolumeVarianceMetric
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 = VolumeVarianceMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])There is ONE optional parameter specific to the VolumeVarianceMetric, on top of the common voice metric parameters:
- [Optional]
max_drift_db: an integer for how far, in dB, a reply's volume may rise or fall from its start to its end. Must be greater than0. Defaulted to15.
As a standalone
You can also run the VolumeVarianceMetric 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 volume drifted shows up in score_breakdown as one event. Here is what the example call returns:
{
"eligible_turns": 3,
"turns_with_events": 1,
"events": [
{
"type": "volume_drift",
"turn": 3,
"timing_source": "turn_timestamps",
"description": "Volume faded 17 dB during the reply",
"drift_db": -17.2,
"offset_seconds": 0.0,
"duration_seconds": 7.0,
"start_time": 12.5,
"mark": "whole_reply",
}
],
"skipped": [
{
"turn": 5,
"error": "Reply has under 6 seconds of speech to follow.",
}
],
}| Field | What it means |
|---|---|
drift_db | How much the volume changed across the reply, in dB. Negative for a fade, positive for a swell |
Each event covers the whole reply, so offset_seconds is 0 and duration_seconds is the clip's length. Replies that are too short, silent or 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 drifted. The score is the share that didn't.
How Is It Calculated?
The VolumeVarianceMetric score is calculated according to the following equation:
Which replies are scored
Each reply is cut into 1-second windows. A window is kept when it holds at least 0.3 seconds of speech (15 frames of 20 ms at about −41 dBFS or louder). Windows with less, such as the tail of a word, are left out, as is a last window under 1 second.
A reply is skipped when it:
- has fewer than 6 windows kept, since a steady drift needs several seconds to tell apart from normal rises and falls, or
- has no audible sound at all, which Silent Reply reports instead.
Drift criteria
| Check | Rule |
|---|---|
| Window level | The median of the window's 5 loudest 20 ms frames, so pauses don't pull it down |
| Steady trend | The window levels keep moving one way: their rank correlation with time is 0.8 or more, up or down. If not, the drift is 0 |
| Drift | The trend from the first kept window to the last, using the median slope between every pair of windows |
| Drifted | The drift is more than max_drift_db (15 dB) either way |
Because of the trend check, a reply that dips and comes back, or rises and falls with the sentence, has no drift, however large the dip. Only a fade or swell that keeps going is measured, and the median slope stops one odd window from tilting it.
If no reply is long enough to follow, the metric is skipped.
Example call
A call where one agent reply fades steadily, one dips in the middle and comes back, and one is too short to follow.
| Agent turn | Drift | Drifted? |
|---|---|---|
| 1 | 0.0 dB | No |
| 3 | −17.2 dB | Yes |
| 5 | Under 6 windows | Skipped |
| 7 | 0.0 dB, no steady trend | No |
| 3 replies | 1 drifted → 2/3 = 0.67 |