Audio Clipping
The audio clipping metric checks whether your voice agent's audio is distorted from being too loud, so the voice turns crackly and harsh on loud syllables. It returns the share of agent replies with no clipping, between 0 and 1.
Required Arguments
To use the AudioClippingMetric, 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*.
With per-turn audio, an Audio.start_time on each clip is optional, and only used to place events on the call's clock.
* 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 AudioClippingMetric() 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 AudioClippingMetric
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 = AudioClippingMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])The AudioClippingMetric has no optional parameters of its own. It takes only the common voice metric parameters.
As a standalone
You can also run the AudioClippingMetric 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 clipped reply shows up in score_breakdown as one event. Here is what the example call returns:
{
"eligible_turns": 4,
"turns_with_events": 1,
"events": [
{
"type": "clipping",
"turn": 5,
"role": "assistant",
"offset_seconds": 0.048,
"duration_seconds": 1.657,
"start_time": 12.548,
"mark": "range",
"timing_source": "turn_timestamps",
"description": "Audio was clipped",
"position": "start",
"fraction": 0.0836,
}
],
"skipped": [],
}| Field | What it means |
|---|---|
offset_seconds | Where the first clipped sample is, in seconds from the start of the clip |
duration_seconds | From the first clipped sample to the last |
fraction | The share of the clip's samples that were clipped |
position | Whether the clipped stretch starts near the start, middle or end of the clip |
Clips 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 clipped. The score is the share that weren't.
How Is It Calculated?
The AudioClippingMetric score is calculated according to the following equation:
Clipping criteria
Audio that's too loud hits the top of what a 16-bit sample can hold, called full scale, and gets flattened there.
A reply is clipped when:
| Check | Rule |
|---|---|
| Clipped sample | 32,000 or more either way from zero, near the 32,767 maximum |
| Share of the clip | More than 0.1% of its samples are clipped |
Reviewers heard clipping when as little as 0.1% of a reply's samples sat near full scale, so light clipping counts, but a few clipped samples on one loud syllable don't.
If there's nothing to count, the metric is skipped.
Example call
A call where one of four agent replies is pushed far past full volume.
| Agent turn | What happens | Clipped? |
|---|---|---|
| 1 | Normal volume | No |
| 3 | Three times louder, but every sample stays under 32,000 | No |
| 5 | 8.4% of samples at or near full scale | Yes |
| 7 | Normal volume | No |
| 4 replies | 1 clipped → 3/4 = 0.75 |