Audio Input Agent

Code

1import requests
2from kern.agent import Agent, RunOutput # noqa
3from kern.media import Audio
4from kern.models.openai import OpenAIResponses
5
6# Fetch the audio file and convert it to a base64 encoded string
7url = "https://openaiassets.blob.core.windows.net/$web/API/docs/audio/alloy.wav"
8response = requests.get(url)
9response.raise_for_status()
10wav_data = response.content
11
12# Provide the agent with the audio file and get result as text
13agent = Agent(
14 model=OpenAIResponses(id="gpt-5.2-audio-preview", modalities=["text"]),
15 markdown=True,
16)
17agent.print_response(
18 "What is in this audio?", audio=[Audio(content=wav_data, format="wav")]
19)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export OPENAI_API_KEY=xxx

Install dependencies

1uv pip install -U openai requests kern-ai

Run Agent

1python cookbook/11_models/openai/chat/audio_input_agent.py