Voice AI Systems. Lesson 5. Budget the whole speech path.

This educational session uses fictional healthcare operations examples. This session uses AI narration.

Audio bytes need a contract

A stream of audio bytes is meaningful only with an agreed encoding, sample rate, channel count and framing. A phone interface may use eight-kilohertz mu-law audio, while a model endpoint may expect a different PCM format. Renaming a content type does not convert the samples. Resampling and codec conversion must happen at a defined boundary, with tests for duration, speed, clipping and channel handling.

Twilio's Media Streams documentation, for example, specifies base64-encoded mu-law audio at eight kilohertz for outbound media messages. That is a transport-specific contract, not a universal requirement for every voice model. Base64 expands byte representation; it does not improve sound quality. Accidentally treating encoded data as raw PCM can produce noise even when every network request succeeds.

WebRTC, WebSocket and SIP solve different problems

WebRTC provides a real-time media stack with mechanisms for transport, timing and network adaptation. WebSocket provides a bidirectional message channel, leaving more audio framing, buffering and playback work to the application. SIP is used for session signaling in telephony environments; the actual media and provider integration still have their own contracts. Choosing one of these does not automatically select a speech model or a business workflow.

Measure both directions of the path. Input audio can wait in capture buffers, travel over a network, accumulate at a recognizer and wait for an endpoint decision. Output can wait for reasoning, a tool, synthesis, delivery and a playback buffer. A jitter buffer can smooth irregular arrival while adding delay. Too little buffering risks gaps; too much can make interruptions feel sluggish and leave more stale speech queued.

Separate first sound from useful completion

The calculator models one sequential trace. Add endpoint delay, recognition finalization, reasoning to the first stable phrase, synthesis startup, network allowance and playback buffering to estimate the first acknowledgment. If a useful answer requires a tool result first, add that tool time. Real systems may overlap stages, so the critical path is a dependency graph rather than always a simple sum.

Do not add component ninety-fifth percentiles and call the result the end-to-end ninety-fifth percentile. Quantiles depend on the joint distribution and correlations between stages. Record end-to-end traces under load, then inspect where slow calls spend time. The sum of measured durations for one trace is valid when the stages are sequential; the sum of separately measured marginal quantiles is a different statistic.

Backpressure and cancellation belong in the design

A producer can generate audio faster than the consumer plays it. Without bounded queues, latency and memory grow while stale speech accumulates. Apply backpressure, bound pending audio and cancel obsolete generation when the active turn changes. Keep sequence numbers or response identifiers where the protocol supports them, and ensure a reconnection cannot replay old output into a new conversation.

For a healthcare receptionist, test the path with the real channel conditions before setting a service objective. Include slow backend reads, bursty arrivals, packet loss, device changes and interruptions during buffered output. A laboratory model latency is only one component. Your budget should identify the measured values, assumed allowances, overlap opportunities and failure handling. Optimize the largest verified contributor without quietly weakening task correctness or cutting off callers to make the latency chart look better.

Your decision exercise. A synthetic sequential trace has endpoint delay 250 ms, recognition finalization 120 ms, reasoning 300 ms, tool work 850 ms, synthesis startup 200 ms, network allowance 80 ms and playback buffer 100 ms. The acknowledgment does not wait for the tool; the useful result must. A dashboard separately reports a P95 for each stage. What can you calculate from the trace without mislabeling a percentile?

Option 1. 1,050 ms to acknowledgment and 1,900 ms to a tool-dependent useful answer; measure end-to-end P95 from complete traces.

Option 2. 850 ms to task completion because the tool is the only stage that changes business state.

Option 3. 1,900 ms is necessarily end-to-end P95 because adding component P95 values always preserves the percentile.

Pause here and commit to a choice. Name the decisive evidence and one limitation before continuing.

Reference analysis. The non-tool stages sum to 1,050 ms. Adding the 850 ms tool gives 1,900 ms for this sequential useful-answer path. Those are trace calculations under stated dependencies. An early acknowledgment can improve perceived responsiveness without changing the time at which useful work is complete. P95 requires the end-to-end distribution; component quantiles cannot generally be summed into it. If some stages overlap, redraw the dependency graph and measure its critical path instead of subtracting an arbitrary percentage from the sum.

Now change one fact. Now recognition and reasoning overlap by 150 ms, but the tool result must still precede the final phrase. Recompute the trace. Then explain what additional measurements are needed before claiming that the same reduction occurs at P95 under load.

Draw the path in words from microphone samples to the caller hearing a verified answer. At every stage, name its data format and owner. Include one queue that can grow and one point where cancellation must discard stale data. Finish by explaining why a buffer can improve audio continuity while worsening conversational responsiveness.
