# Voice Pipeline

> The Voice Pipeline is an architecture where speech recognition, a language model and speech synthesis run in sequence.

## How does a voice AI pipeline work?

The architecture where STT converts speech to text, an LLM generates the answer and TTS speaks it. Each part can be chosen and tested separately, but delays add up, so every step is streamed.

- Topic: Voice AI
- Type: architecture

## Example

Wrong:

```js
const text = await transcribe(audio);
const answer = await complete(text);
const speech = await synthesize(answer);
play(speech);
```

Right:

```js
const text = await transcribeStream(micStream);
for await (const sentence of completeStream(text)) {
  playQueued(synthesizeStream(sentence));
}
```

Streaming the LLM answer into TTS sentence by sentence lets speech start before the full answer is generated.

## Common mistakes

- Measuring only model speed and ignoring the total time from end of speech to first sound.

## Key points

- Each stage streams into the next instead of waiting for complete results.
- The LLM's answers are short and conversational, as they are spoken.

## Interview questions

### What latency is acceptable for a voice agent?

Conversation feels natural when the reply starts within about a second after the user stops speaking. Longer gaps feel like the agent did not hear.

### How do I measure voice pipeline latency?

Measure from the end of user speech to the first audio byte played back, and log the time of each stage to see which one is slow.

### Voice pipeline vs speech-to-speech: which should I use?

A pipeline gives more control and easier debugging. Speech-to-speech gives lower latency and more natural tone, but less visibility into each step.

## Related cards

- [Speech-to-Text](https://wonderium.dev/ai/speech-to-text.md)
- [Text-to-Speech](https://wonderium.dev/ai/text-to-speech.md)
- [Speech-to-Speech](https://wonderium.dev/ai/speech-to-speech.md)
- [Latency](https://wonderium.dev/ai/latency.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/voice-pipeline
- Last updated: 2026-11-25
