Loudness Consistency
The loudness consistency metric checks whether your voice agent keeps the same volume from one reply to the next, rather than one reply being clearly louder or quieter than the rest. It returns the share of agent replies that stay close to the agent's typical loudness, between 0 and 1.
Required Arguments
To use the LoudnessConsistencyMetric, you'll have to provide a ConversationalTestCase with audio on at least three of 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 LoudnessConsistencyMetric() 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 LoudnessConsistencyMetric
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 = LoudnessConsistencyMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])There is ONE optional parameter specific to the LoudnessConsistencyMetric, on top of the common voice metric parameters:
- [Optional]
max_shift_db: an integer for how far, in dB, a reply's loudness may sit from the agent's typical loudness. Must be greater than0. Defaulted to7.
As a standalone
You can also run the LoudnessConsistencyMetric 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 that was clearly louder or quieter than usual shows up in score_breakdown as one event. Here is what the example call returns:
{
"eligible_turns": 4,
"turns_with_events": 1,
"events": [
{
"type": "loudness_shift",
"turn": 5,
"timing_source": "turn_timestamps",
"description": "Reply was 8 dB quieter than usual",
"speech_dbfs": -27.1,
"shift_db": -7.9,
"offset_seconds": 0.0,
"duration_seconds": 3.0,
"start_time": 14.5,
"mark": "whole_reply",
}
],
"skipped": [],
}| Field | What it means |
|---|---|
speech_dbfs | The reply's speech level, in dBFS |
shift_db | How far that sits from the agent's typical level. Negative when quieter |
Each event covers the whole reply, so offset_seconds is 0 and duration_seconds is the clip's length. Replies with under 1 second of speech, including silent ones, and replies 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 were off. The score is the share that weren't.
How Is It Calculated?
The LoudnessConsistencyMetric score is calculated according to the following equation:
Which replies are scored
A reply is compared if its speech spans at least 1 second, the same rule Loudness uses. A reply with no audible sound at all is left to Silent Reply.
At least 3 such replies are needed to tell which one is off. With fewer, the metric is skipped.
Shift criteria
Each reply's speech level is measured as in Loudness: the 90th percentile of its 20 ms frames at speech volume. The agent's typical level is the median across its replies, so one odd reply is flagged instead of shifting what counts as typical.
| Check | Rule |
|---|---|
| Shift | The reply's speech level minus the typical level |
| Off | The shift is more than max_shift_db (7 dB) either way |
Example call
A call where one agent reply comes out much quieter than the rest. The agent's typical level is −19.2 dBFS.
| Agent turn | Speech level | Shift | Off? |
|---|---|---|---|
| 1 | −19.2 dBFS | 0.0 dB | No |
| 3 | −19.2 dBFS | 0.0 dB | No |
| 5 | −27.1 dBFS | −7.9 dB | Yes |
| 7 | −18.4 dBFS | +0.8 dB | No |
| 4 replies | 1 off → 3/4 = 0.75 |