Loudness
The loudness metric checks whether your voice agent speaks too quietly or too loudly, for example so quietly that the caller has to turn the volume up. It returns the share of agent replies whose speech level falls inside an accepted range, between 0 and 1.
Required Arguments
To use the LoudnessMetric, 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 LoudnessMetric() 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 LoudnessMetric
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 = LoudnessMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])There are TWO optional parameters specific to the LoudnessMetric, on top of the common voice metric parameters:
- [Optional]
min_dbfs: an integer for the quietest speech level a reply may have, in dBFS (decibels relative to full scale, where 0 is the loudest a digital sample can be). Must be lower thanmax_dbfs. Defaulted to-32. - [Optional]
max_dbfs: an integer for the loudest speech level a reply may have, in dBFS. Must be0or lower. Defaulted to-10.
As a standalone
You can also run the LoudnessMetric 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 too quiet or too loud shows up in score_breakdown as one event. Here is what the example call returns:
{
"eligible_turns": 4,
"turns_with_events": 2,
"events": [
{
"type": "too_quiet",
"turn": 3,
"timing_source": "turn_timestamps",
"description": "Reply was too quiet (-36 dBFS)",
"speech_dbfs": -35.7,
"offset_seconds": 0.0,
"duration_seconds": 3.0,
"start_time": 8.5,
"mark": "whole_reply",
},
{
"type": "too_loud",
"turn": 7,
"timing_source": "turn_timestamps",
"description": "Reply was too loud (-4 dBFS)",
"speech_dbfs": -4.2,
"offset_seconds": 0.0,
"duration_seconds": 3.0,
"start_time": 20.5,
"mark": "whole_reply",
},
],
"skipped": [],
}| Field | What it means |
|---|---|
type | Too quiet or too loud |
speech_dbfs | The reply's speech level, in dBFS |
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 counted and turns_with_events how many were out of range. The score is the share that weren't.
How Is It Calculated?
The LoudnessMetric score is calculated according to the following equation:
Which replies are scored
A reply is scored if its speech spans at least 1 second, from the first to the last 20 ms frame louder than silence (about −41 dBFS). A shorter reply, such as a lone "mm-hm", is too brief for its level to mean much. A reply with no audible sound at all is left to Silent Reply.
Loudness criteria
Each reply is cut into 20 ms frames. Its speech level is the 90th percentile of the frames at speech volume (about −41 dBFS or louder), so pauses don't make a reply look quiet.
| Check | Rule |
|---|---|
| Too quiet | Speech level below min_dbfs (−32 dBFS) |
| Too loud | Speech level above max_dbfs (−10 dBFS) |
If no reply has at least 1 second of decodable speech, the metric is skipped.
Example call
A call where one agent reply is far too quiet and one is far too loud.
| Agent turn | Speech level | Out of range? |
|---|---|---|
| 1 | −19.2 dBFS | No |
| 3 | −35.7 dBFS | Yes (too quiet) |
| 5 | −19.2 dBFS | No |
| 7 | −4.2 dBFS | Yes (too loud) |
| 4 replies | 2 out of range → 2/4 = 0.5 |
FAQs
How is this different from Speech Intelligibility?
Does a loud, distorted reply count here and in Audio Clipping?
When should I change the limits?
min_dbfs=-28, max_dbfs=-16, to catch smaller drifts from your target.