Skip to main content
Stream your microphone to Dialog-RSN-1 through the official openai SDK, and print each thing you say as a line of text. The program opens a transcription session, which transcribes every turn and never replies. You pay for each turn’s audio and its transcript, and there are no instructions to write. Transcription works in any language, and you name the caller’s language with an ISO 639 code. The second part of this guide keeps the same audio path and opens a realtime session instead, so a support agent hears the caller and answers in text.

Full code on GitHub

A terminal transcriber, and a voice-in, text-out support agent, in Python and Node.

What you’ll build

  1. A transcriber, in Python and Node. Speak, and each finished sentence prints with a timestamp. The Python version can also append each line to a file.
  2. A support agent, in Python and Node. Speak, and Sam from a fictional outdoor store answers in text about three orders held in the prompt.

Prerequisites

  1. A Dialog-RSN-1 API key. Sign up or log in at studio.poly.ai and create one in the API Keys tab. The quickstart walks through it.
  2. For Python: Python 3.12 and uv.
  3. For Node: Node 22. npm install compiles the naudiodon2 audio package, so you need a C++ toolchain.
  4. A microphone, or a 24 kHz, 16-bit mono WAV file to stream instead.

Connect

Pass the Dialog-RSN-1 base URL and key to the client, and ask for a transcription session when you connect. url is the full realtime URL, so drop /realtime and switch the scheme to get the base. The SDK sends the key as Authorization: Bearer and parses every event into its typed models.
url defaults to wss://api.studio.poly.ai/v1/realtime. Set DIALOG_REALTIME_URL in .env, or pass --url, to point somewhere else.

Configure the session

Send a session.update with type: "transcription":
  • transcription.language is the caller’s language, as an ISO 639 code such as es for Spanish or en-US. Both programs take it as --language and default to en.
  • rate: 24000. The program opens the microphone at 24 kHz, so nothing resamples on the client. The service resamples to the model’s own rate.
  • turn_detection: {"type": "server_vad"}. Each turn ends at a pause, and turn_detection.silence_duration_ms sets how long that pause is (400 ms by default). A caller who pauses longer than that mid-sentence gets two lines, so raise it for slow speakers. To decide where turns end yourself, set turn_detection to null and send input_audio_buffer.commit.
session.updated echoes the session back, with type: "transcription". Each turn is transcribed on its own, and transcripts arrive in the order the turns were spoken.

Stream the microphone

The program reads 100 ms of PCM16 at a time, base64-encodes each chunk, and appends it to the input buffer:
The program never commits the buffer. The server commits each turn when the caller pauses.

Read the transcript

For each turn, the server sends input_audio_buffer.speech_started, then input_audio_buffer.speech_stopped and input_audio_buffer.committed at the pause. Then the transcript arrives on two events. conversation.item.input_audio_transcription.delta streams it in pieces, and conversation.item.input_audio_transcription.completed carries the whole line with its usage in tokens. A turn that can’t be transcribed ends with .failed instead.
The deltas show the line as it arrives, and .completed replaces it with the final text. In Python, line() stamps the text with the time, prints it and appends it to the --out file. Stop on invalid_request_error. It usually means the session.update was refused, which leaves the session on the server’s defaults:

Run it

Speak, and each line prints when you pause:
Pass --language es (npm run transcribe -- --language es in Node) for a Spanish speaker, or any other ISO 639 code. In Python, add --out notes.txt to append each line to a file. To test without a microphone, record a clip with the macOS say command and stream it at real time:

Build a voice-in, text-out agent

A transcription session never replies. For an agent that hears the caller and answers, open a normal realtime session. support_agent.py and support_agent.js keep the client and the audio path, and change the session. A realtime session with text output. Connect with model only, without intent=transcription, and send this session:
output_modalities: ["text"] puts the reply on response.output_text.*. A new session defaults to ["audio"], where the server speaks the reply and sends its words as response.output_audio_transcript.*. With create_response: true, Dialog-RSN-1 decides when the caller has finished and starts the reply itself. The instructions. prompt.py and prompt.js hold everything Sam knows: three orders in different states, the return and cancellation policy, and a rule to confirm the order before giving details. There are no tools, and the data sits in the prompt. Dialog-RSN-1 hears the caller with the prompt in front of it, so the order numbers and names in it help it hear them correctly. See speech understanding. A seeded greeting. The program prints the greeting itself and adds it to the conversation as an assistant message, so the model’s history starts with it:
The reply waits for the transcript. In a realtime session, Dialog-RSN-1 transcribes the caller in the same generation that answers the turn, and the transcript can arrive after the reply has started. Printed in arrival order, the answer would sit above the question, so the program buffers the reply until your line has printed:
Run it, in either language:
Say “I’m calling about order N W one zero four eight two, it’s under Maria Alvarez”, then “Can I still cancel it?”. That order has shipped, so Sam refuses and points you to a return:
Every program takes --file call.wav to stream a recording instead of the microphone, and --list-devices and --device to pick a microphone.

Troubleshooting

Where to go next

Last modified on November 24, 2026