Audio Loop
The audio loop metric checks whether your voice agent's audio gets stuck repeating the same chunk, as in "Your order, your order, your order". It returns the share of agent replies with no loop, between 0 and 1.
Required Arguments
To use the AudioLoopMetric, 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 AudioLoopMetric() 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 AudioLoopMetric
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 = AudioLoopMetric(threshold=0.8)
evaluate(test_cases=test_cases, metrics=[metric])The AudioLoopMetric has no optional parameters of its own. It takes only the common voice metric parameters.
As a standalone
You can also run the AudioLoopMetric 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 loop shows up in score_breakdown as its own event. Here is what the example call returns:
{
"eligible_turns": 4,
"turns_with_events": 1,
"events": [
{
"type": "audio_loop",
"turn": 3,
"offset_seconds": 1.25,
"duration_seconds": 0.76,
"start_time": 8.75,
"mark": "range",
"timing_source": "turn_timestamps",
"description": "Audio repeated for 0.8s",
}
],
"skipped": [],
}Loop events carry only the fields all voice events share. offset_seconds is where the first repeat starts, and duration_seconds covers every repeat after the original. Clips that can't be decoded are listed under skipped.
eligible_turns is how many agent replies were counted and turns_with_events how many had a loop. A reply with several loops counts once. The score is the share that had none.
How Is It Calculated?
The AudioLoopMetric score is calculated according to the following equation:
Loop criteria
A loop is a chunk of audio that plays three or more times in a row. Matching compares how alike the sound is, not exact bytes, so a loop is still found after the audio is re-encoded on its way through the call.
| Check | Rule |
|---|---|
| Chunk length | 0.2 to 2 seconds, and no more than a third of the clip |
| Match | Each 40 ms of the chunk matches the same 40 ms one chunk later, at 0.9 correlation or more |
| Repeats | The match holds for at least two chunk lengths, so the chunk plays three times |
| Not a steady sound | The level inside the chunk varies by at least 3 dB |
Near-silent moments neither confirm nor break a match, so pauses inside a repeated phrase don't split it. A steady drone matches itself at every delay, so the last check leaves it to Held Tone.
If there's nothing to count, the metric is skipped.
Example call
A call where one of four agent replies gets stuck on a quarter-second syllable.
| Agent turn | What happens | Loop? |
|---|---|---|
| 1 | Normal speech | No |
| 3 | A 0.25 s syllable plays four times in a row, from 1 s into the clip | Yes |
| 5 | Normal speech | No |
| 7 | Normal speech | No |
| 4 replies | 1 loop → 3/4 = 0.75 |