Audio Input (Local file)

Code

1from pathlib import Path
2from kern.agent import Agent
3from kern.media import Audio
4from kern.models.google import Gemini
5
6agent = Agent(
7 model=Gemini(id="gemini-2.0-flash-exp"),
8 markdown=True,
9)
10
11# Please download a sample audio file to test this Agent and upload using:
12audio_path = Path(__file__).parent.joinpath("sample.mp3")
13
14agent.print_response(
15 "Tell me about this audio",
16 audio=[Audio(filepath=audio_path)],
17 stream=True,
18)

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 GOOGLE_API_KEY=xxx

Install dependencies

1uv pip install -U google-genai kern-ai

Run Agent

1python cookbook/11_models/google/gemini/audio_input_local_file_upload.py