> ## Documentation Index
> Fetch the complete documentation index at: https://www.vobiz.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Speechmatics + Vobiz | Voice Agents and Live Call Transcription

> Answer Vobiz phone calls with a Speechmatics voice agent (agent STT, an LLM and streamed TTS), or transcribe both sides of a live call as separate speakers with the Speechmatics Realtime API.

![Speechmatics](https://mintcdn.com/vobizai/mSXuKRqEOitZsQmi/images/speechmatics/logo.png?fit=max\&auto=format\&n=mSXuKRqEOitZsQmi\&q=85\&s=a41191a03f49bbd6f6ee3eb1acde17c1)

[Speechmatics](https://www.speechmatics.com/) builds speech recognition and speech synthesis for real-time voice: [agent STT](https://docs.speechmatics.com/speech-to-text/agent-stt) (Linden 1) for voice agents, the [Realtime API](https://docs.speechmatics.com/speech-to-text/realtime/quickstart) for live transcription, and [Text to Speech](https://docs.speechmatics.com/text-to-speech/quickstart). A Vobiz [`<Stream>`](https://www.vobiz.ai/docs/xml/stream) sends live call audio to your server as 16-bit PCM at 16 kHz, which Speechmatics accepts as it is, so nothing is transcoded.

**Source code:** [vobiz-ai/Vobiz-Speechmatics](https://github.com/vobiz-ai/Vobiz-Speechmatics), two Python examples that each run as a single process, with no voice-agent framework or media server. The same examples are in the [Speechmatics Academy](https://github.com/speechmatics/speechmatics-academy/tree/main/integrations/vobiz).

| Example | What you'll build |
| - | - |
| [Phone voice agent](#phone-voice-agent) | A number answered by an AI agent: Speechmatics agent STT hears each caller turn, an OpenAI-compatible LLM writes the reply, and Text to Speech speaks it back into the call. The caller can interrupt. |
| [Live call transcription](#live-call-transcription) | A call to your number is bridged to a second phone, and both sides are transcribed live as separate speakers, in the console and on a live web page. |

> [!NOTE]
>
> **Scope:** inbound and outbound. Both examples answer calls to your Vobiz number, and both can place an outbound call (`dial.py`, `proxy.py --call`).

## Requirements

* A Vobiz account with a voice-enabled number, and your **Auth ID** and **Auth Token** from the [Vobiz console](https://console.vobiz.ai).
* A Speechmatics API key from the [Speechmatics portal](https://portal.speechmatics.com/).
* Python 3.12.
* A public HTTPS tunnel to your machine, such as [ngrok](https://ngrok.com/) or [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/).
* For the voice agent: an API key for an OpenAI-compatible LLM ([Gemini](https://aistudio.google.com/apikey) by default, or OpenAI). Optionally an ElevenLabs or Cartesia key, if you choose that voice instead of Speechmatics TTS.
* For live transcription: a second phone for Vobiz to bridge the call to.

```bash theme={null}
git clone https://github.com/vobiz-ai/Vobiz-Speechmatics.git
cd Vobiz-Speechmatics
```

***

## Phone voice agent

A caller dials your Vobiz number and talks to an AI agent. The agent listens with Speechmatics agent STT, replies with an LLM, and speaks with streamed Text to Speech: [Speechmatics TTS](https://docs.speechmatics.com/text-to-speech/quickstart) by default, or ElevenLabs or Cartesia.

### How it works

```mermaid theme={null}
flowchart LR
    PHONE[Caller] <-->|PSTN| VOBIZ[Vobiz]
    VOBIZ <-->|"Stream WebSocket<br/>16 kHz PCM both ways"| SERVER[main.py]
    SERVER -->|caller audio| STT["Speechmatics agent STT<br/>Linden 1"]
    STT -->|"AddSegment, EndOfTurn"| SERVER
    SERVER <-->|"turn text / reply"| LLM["LLM<br/>OpenAI-compatible"]
    SERVER -->|each sentence| TTS["Text to Speech"]
    TTS -->|16 kHz PCM| SERVER
```

1. Vobiz fetches `/answer/<token>` and receives a bidirectional `<Stream>` that points at `/ws/<token>`.
2. Caller audio arrives as 20 ms `media` frames of 16-bit PCM, and the server forwards them to agent STT.
3. Agent STT returns `AddSegment` messages and an `EndOfTurn` when the caller has finished. A custom dictionary keeps brand names such as "Vobiz" spelled correctly.
4. The LLM reply is split into sentences. Each sentence goes to Text to Speech as raw 16 kHz PCM and streams back to Vobiz in `playAudio` messages, so the caller hears the first sentence while the rest is still being written.
5. **Interruptions:** any sound from the caller pauses the agent with `clearAudio`, but keeps the reply. If the caller says words, the reply is dropped; if no words follow within 2 seconds (a cough, an "mhm"), the agent carries on from the sentence it was cut off in.
6. When the LLM ends its goodbye, the server sends a `checkpoint`, waits for Vobiz to confirm the goodbye has played, then sends `stop` to hang up.

### Step 1: Install and configure

```bash macOS / Linux theme={null}
cd 01-phone-voice-agent/python
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
cp ../.env.example .env
```

```powershell Windows theme={null}
cd 01-phone-voice-agent\python
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
Copy-Item ..\.env.example .env
```

Start a tunnel to port 8765 in a second terminal (`ngrok http 8765`) and copy its `https://` URL. Then set these in `python/.env`:

```bash .env theme={null}
SPEECHMATICS_API_KEY=your_speechmatics_key
GEMINI_API_KEY=your_gemini_key
PUBLIC_URL=https://your-tunnel.ngrok-free.app

# Only for outbound calls with dial.py
VOBIZ_AUTH_ID=MA_XXXXXXXX
VOBIZ_AUTH_TOKEN=YOUR_AUTH_TOKEN
VOBIZ_FROM_NUMBER=+910000000000
```

To use OpenAI instead of Gemini, or ElevenLabs or Cartesia instead of Speechmatics TTS, follow the commented options in `.env.example`.

### Step 2: Run it

```bash theme={null}
python main.py
```

It prints the answer and hangup URLs:

```text theme={null}
Answer URL: https://your-tunnel.ngrok-free.app/answer/Xq3...
Hangup URL: https://your-tunnel.ngrok-free.app/hangup/Xq3...
TTS: Speechmatics (sarah)  LLM: gemini-3.1-flash-lite  Listening on http://127.0.0.1:8765
```

### Step 3: Place a call

> [tab] Call the agent
>
> **1. Create an application**
>
> In the [Vobiz console](https://console.vobiz.ai), create a Voice Application with the printed **Answer URL** and **Hangup URL**, method `POST`.
>
> **2. Attach your number**
>
> Attach your Vobiz number to the application.
>
> **3. Call it**
>
> Dial the number from any phone and start talking.

> [tab] Have the agent call you
>
> In a third terminal, from `01-phone-voice-agent/python` with the virtual environment active:
>
> ```bash theme={null}
> python dial.py +91XXXXXXXXXX --answer-url https://your-tunnel.ngrok-free.app/answer/Xq3...
> ```
>
> Your phone rings from `VOBIZ_FROM_NUMBER`. Outbound calls are billed to your Vobiz account.

### What you'll see

Output from a call:

```text theme={null}
CALL      started call=4b0c... format={'encoding': 'audio/x-l16', 'sampleRate': 16000}
STT       Speechmatics session started 1b4f6675-...
AGENT     Hi, I'm Vee, the Vobiz voice assistant. ... What would you like to know?
CALLER    Can you tell me in one sentence what Vobiz is?
AGENT     Vobiz is a cloud telephony platform that provides phone numbers, voice calls, and tools for call control.
PAUSE     caller made a sound over the agent, pausing until words follow
RESUME    no words followed, carrying on from: It handles calls through the cloud.
BARGE-IN  caller spoke over the agent, dropping the reply
CALL      goodbye played, ending the call
CALL      ended
```

| Label | Meaning |
| - | - |
| `CALLER` / `AGENT` | One finished caller turn, and the agent's reply |
| `PAUSE` | A sound over the agent: playback paused, reply kept |
| `RESUME` | No words followed within 2 seconds: the agent carries on |
| `BARGE-IN` | The caller said words over the agent: the reply is dropped |

### The answer XML

```xml theme={null}
<Response>
  <Stream bidirectional="true" keepCallAlive="true" audioTrack="inbound"
          contentType="audio/x-l16;rate=16000">wss://your-tunnel.ngrok-free.app/ws/Xq3...</Stream>
</Response>
```

| Attribute | Value | Why |
| - | - | - |
| `bidirectional` | `true` | The server plays the agent's voice back into the call with `playAudio` |
| `keepCallAlive` | `true` | Keeps the call up for as long as the stream is open |
| `audioTrack` | `inbound` | The caller's audio only; required with `bidirectional="true"` |
| `contentType` | `audio/x-l16;rate=16000` | 16-bit PCM at 16 kHz, the format agent STT takes |

> [!WARNING]
>
> Send `playAudio` with only `event` and `media`. Vobiz plays it on the stream it arrives on. `checkpoint`, `clearAudio` and `stop` carry the `streamId` from the `start` event.

### Configuration reference

| Variable | Default | Description |
| - | - | - |
| `SPEECHMATICS_API_KEY` | required | Speechmatics key, for agent STT and Speechmatics TTS |
| `GEMINI_API_KEY` | required (default LLM) | Gemini key; or set `LLM_API_KEY` for another provider |
| `PUBLIC_URL` | required | Your tunnel's `https://` URL |
| `TTS_PROVIDER` | `speechmatics` | `speechmatics`, `elevenlabs` or `cartesia` |
| `SM_VOICE` | `sarah` | Speechmatics voice: `sarah`, `theo` (UK English), `megan`, `jack` (US English) |
| `ELEVENLABS_API_KEY` / `ELEVENLABS_MODEL` / `ELEVENLABS_VOICE_ID` | unset / `eleven_flash_v2_5` / George | ElevenLabs settings, when `TTS_PROVIDER=elevenlabs` |
| `CARTESIA_API_KEY` / `CARTESIA_MODEL` / `CARTESIA_VOICE_ID` | unset / `sonic-3.6` / Gemma | Cartesia settings, when `TTS_PROVIDER=cartesia` |
| `SM_LANGUAGE` | `en` | Agent STT language |
| `SPEECHMATICS_RT_URL` | `wss://eu2.rt.speechmatics.com/v2` | Agent STT region endpoint |
| `LLM_BASE_URL` | Gemini's OpenAI-compatible URL | Any OpenAI-compatible base URL, such as `https://api.openai.com/v1` |
| `LLM_API_KEY` | `GEMINI_API_KEY` | Key for `LLM_BASE_URL` |
| `LLM_MODEL` | `gemini-3.1-flash-lite` | Chat model |
| `LLM_REASONING_EFFORT` | `minimal` | Set it empty for models that reject the field |
| `LLM_TEMPERATURE` | `0.6` | Set `default` for models that accept only their default temperature |
| `PORT` | `8765` | Local port |
| `PATH_TOKEN` | random per run | Secret path segment for the answer URL and WebSocket |
| `MAX_CALLS` | `5` | Calls handled at once |
| `MAX_CALL_SECONDS` | `600` | Longest a call can last before the agent ends it |
| `VOBIZ_AUTH_ID` / `VOBIZ_AUTH_TOKEN` / `VOBIZ_FROM_NUMBER` | unset | Only for outbound calls with `dial.py` |

What the agent knows and how it talks is in `assets/agent.md`.

> [!NOTE]
>
> Speechmatics TTS speaks English voices. Agent STT supports the languages in the [agent STT documentation](https://docs.speechmatics.com/speech-to-text/agent-stt); set `SM_LANGUAGE` to change it.

***

## Live call transcription

Someone calls your Vobiz number and Vobiz bridges them to a second phone. While they talk, Vobiz copies both sides of the call to a local proxy, which sends them to one Speechmatics Realtime session with [channel diarization](https://docs.speechmatics.com/speech-to-text/features/diarization). Each person is transcribed as a separate speaker, in the console and on a live web page.

### How it works

```mermaid theme={null}
flowchart LR
    A[Caller A] <-->|PSTN| VOBIZ[Vobiz]
    VOBIZ <-->|Dial bridge| B[Caller B]
    VOBIZ -->|"Stream audioTrack=both<br/>16 kHz PCM, one-way"| PROXY[proxy.py]
    PROXY -->|"inbound + outbound channels"| SM["Speechmatics Realtime<br/>channel diarization"]
    SM -->|transcripts per channel| PROXY
    PROXY --> UI[Console and live web page]
```

1. Vobiz fetches `/answer/<token>` and gets a one-way `<Stream audioTrack="both">`, a short `<Speak>` notice and a `<Dial>` to the second phone. A one-way stream does not block, so the call moves straight on to the notice and the bridge.
2. Vobiz sends `media` frames labelled `inbound` or `outbound`, each 20 ms of 16-bit PCM at 16 kHz.
3. The proxy queues each frame for its channel, and one `AsyncMultiChannelClient` session transcribes both, tagging each transcript with its channel.
4. When the call ends, Vobiz closes the WebSocket (it sends no stop event). The proxy closes both channels and Speechmatics returns the final words.

### Step 1: Install and configure

```bash macOS / Linux theme={null}
cd 02-live-call-transcription/python
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
cp ../.env.example .env
```

```powershell Windows theme={null}
cd 02-live-call-transcription\python
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
Copy-Item ..\.env.example .env
```

Set these in `python/.env`:

```bash .env theme={null}
SPEECHMATICS_API_KEY=your_speechmatics_key
NGROK_AUTHTOKEN=your_ngrok_token        # or PUBLIC_URL=https://your-tunnel...
VOBIZ_AUTH_ID=MA_XXXXXXXX
VOBIZ_AUTH_TOKEN=YOUR_AUTH_TOKEN
VOBIZ_PHONE_NUMBER=+910000000000        # your Vobiz number
FORWARD_TO_NUMBER=+910000000001         # the phone the call is bridged to
```

### Step 2: Run it

```bash theme={null}
python proxy.py
```

> [!WARNING]
>
> On startup the proxy creates or updates a Vobiz application named `speechmatics-transcription-<number>` and attaches `VOBIZ_PHONE_NUMBER` to it. If the number was attached to another application, it prints that application's ID so you can re-attach it later. Run with `--no-setup` to leave the number's routing alone.

### Step 3: Place a call

Open the printed **Live transcript UI** link in a browser, then call `VOBIZ_PHONE_NUMBER` from any phone. You hear "This call is being transcribed", `FORWARD_TO_NUMBER` rings, and once it is answered both sides are transcribed live.

To have Vobiz place the first call instead, run `python proxy.py --call +91XXXXXXXXXX`. When that person answers, they are bridged to `FORWARD_TO_NUMBER` the same way. Bridged calls are billed to your Vobiz account.

### What you'll see

```text theme={null}
Listening on ws://localhost:5000/vobiz/<token>
Live transcript UI: http://localhost:5000/ui/<token>
Vobiz number +91XXXXXXXXXX pointed at https://xxxx.ngrok-free.app/answer/<token>. Call it now.

[vobiz] call started - tracks=['inbound', 'outbound'] format=audio/x-l16/16000
[outbound] This call is being transcribed.
[inbound ] Hello. Can you hear me?
[outbound] Yes, loud and clear.
[inbound ] Great.
[vobiz] call ended
```

| Label | Who |
| - | - |
| `inbound` | The person who called your Vobiz number (with `--call`, the person Vobiz called) |
| `outbound` | The person the call was bridged to; the notice also plays on this track |

### The answer XML

```xml theme={null}
<Response>
  <Stream audioTrack="both" contentType="audio/x-l16;rate=16000">wss://xxxx.ngrok-free.app/vobiz/&lt;token&gt;</Stream>
  <Speak>This call is being transcribed.</Speak>
  <Dial callerId="+910000000000" timeout="30" timeLimit="3600">
    <Number>+910000000001</Number>
  </Dial>
</Response>
```

| Attribute | Value | Why |
| - | - | - |
| `audioTrack` | `both` | Copies the caller and the bridged party as two separate tracks |
| `bidirectional` | not set | The stream is one-way: the proxy only listens, so the call carries on to `<Speak>` and `<Dial>` |
| `contentType` | `audio/x-l16;rate=16000` | 16-bit PCM at 16 kHz, which the Realtime API accepts directly |
| `<Dial callerId>` | your Vobiz number | Caller ID for the bridged leg; it must be a number on your account |

> [!WARNING]
>
> Don't add `bidirectional="true"` here. A bidirectional stream carries only the inbound track and holds the call on the stream, so the bridge never happens.

### Configuration reference

| Variable | Default | Description |
| - | - | - |
| `SPEECHMATICS_API_KEY` | required | Speechmatics key |
| `VOBIZ_AUTH_ID` / `VOBIZ_AUTH_TOKEN` | required | Vobiz credentials, to configure the number and place calls |
| `VOBIZ_PHONE_NUMBER` | required | Your Vobiz number, in E.164 |
| `FORWARD_TO_NUMBER` | required | The phone the call is bridged to, in E.164 |
| `NGROK_AUTHTOKEN` | unset | Starts an ngrok tunnel when `PUBLIC_URL` is not set |
| `PUBLIC_URL` | unset | Your own `https://` tunnel |
| `SPEECHMATICS_LANGUAGE` | `en` | Transcription language, for example `hi` for Hindi |
| `SM_VOBIZ_PROXY_PORT` | `5000` | Local port |
| `MAX_CALL_SECONDS` | `3600` | Longest a bridged call can last |

| Option | Effect |
| - | - |
| `--call NUMBER` | Place an outbound call to `NUMBER` and bridge it to `FORWARD_TO_NUMBER`; the number's routing is not changed |
| `--no-setup` | Only serve the answer URL and the web page; configure the number in Vobiz yourself |

***

## Security

The audio WebSocket is not signed, so both examples put a random path token in the answer URL, the hangup URL and the WebSocket path. The token changes on every run unless you set `PATH_TOKEN` (voice agent). Anyone with the token can open the stream, and for live transcription read every call's transcript, so keep the URLs private. Neither example validates Vobiz webhook signatures: add [signature validation](https://www.vobiz.ai/docs/concepts/validating-callbacks.md) before exposing a server for anything other than a test. Keep API keys in `.env`, which is ignored by git.

## Troubleshooting

> [accordion] The call connects, then hangs up at once
>
> Vobiz could not fetch the answer URL. Check that the tunnel forwards to the right port (8765 for the voice agent, 5000 for transcription) and that the application's answer URL matches the one printed, including the token. Restarting without `PATH_TOKEN` generates a new token.

> [accordion] The voice agent is silent
>
> Look for `could not start a Speechmatics session` or `TTS error` in the log and check `SPEECHMATICS_API_KEY`. For ElevenLabs, use the secret key that starts with `sk_`, not the key's ID.

> [accordion] LLM error 400 or 404
>
> Check `LLM_MODEL` is available to your key. If the error mentions `reasoning_effort`, set `LLM_REASONING_EFFORT=` (empty); if it mentions `temperature`, set `LLM_TEMPERATURE=default`.

> [accordion] The agent stops too often
>
> Any sound pauses the agent for up to 2 seconds, and each new burst of background noise restarts the pause. Test from a quiet room first.

> [accordion] The caller hears the notice, then the call ends
>
> The bridge did not connect. Check that `FORWARD_TO_NUMBER` is in E.164 form and that your account can call it; the call record in the Vobiz console shows the hangup cause.

> [accordion] No transcripts appear
>
> If you heard the notice, Vobiz reached `/answer`. Check that the proxy printed `call started`; if it did, check `SPEECHMATICS_API_KEY`.

> [accordion] Could not configure the Vobiz number: 401, or number not found
>
> Check `VOBIZ_AUTH_ID` and `VOBIZ_AUTH_TOKEN`, and that `VOBIZ_PHONE_NUMBER` is in E.164 form and belongs to that account.

> [accordion] Address already in use on macOS
>
> macOS uses port 5000 for AirPlay Receiver. Set `SM_VOBIZ_PROXY_PORT=5050`.

## Next steps

> [card] [Stream XML](https://www.vobiz.ai/docs/xml/stream.md)
>
> Every `<Stream>` attribute, event and audio format.

> [card] [Source code](https://github.com/vobiz-ai/Vobiz-Speechmatics)
>
> Both examples, with tests, on GitHub.

> [card] [Dial XML](https://www.vobiz.ai/docs/xml/dial.md)
>
> Bridge calls to another number or SIP endpoint.

> [card] [Other AI voice platforms](https://www.vobiz.ai/docs/integrations.md)
>
> Every Vobiz integration in one place.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.