Audio Sentiment Analysis
Analyze speaker sentiment in a recorded conversation with Gemini, then ask a follow-up question answered from SQLite-backed session history.
Audio Sentiment Analysis.
"""
Audio Sentiment Analysis
=============================
Audio Sentiment Analysis.
"""
import requests
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.media import Audio
from agno.models.google import Gemini
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=Gemini(id="gemini-3.5-flash"),
add_history_to_context=True,
markdown=True,
db=SqliteDb(
session_table="audio_sentiment_analysis_sessions",
db_file="tmp/audio_sentiment_analysis.db",
),
)
url = "https://agno-public.s3.amazonaws.com/demo_data/sample_conversation.wav"
response = requests.get(url)
audio_content = response.content
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# Give a sentiment analysis of this audio conversation. Use speaker A, speaker B to identify speakers.
agent.print_response(
"Give a sentiment analysis of this audio conversation. Use speaker A, speaker B to identify speakers.",
audio=[Audio(content=audio_content)],
stream=True,
)
agent.print_response(
"What else can you tell me about this audio conversation?",
stream=True,
)Declare the WAV format
The downloaded file contains WAV audio. Before running, replace Audio(content=audio_content) with:
Audio(content=audio_content, format="wav")Without format, this Gemini adapter labels the raw bytes as MP3. The second question uses the prior textual conversation from session history.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-genai requests sqlalchemyExport your Google API key
export GOOGLE_API_KEY="your_google_api_key_here"Run the example
Save the code above as audio_sentiment_analysis.py, then run:
python audio_sentiment_analysis.pyFull source: cookbook/02_agents/12_multimodal/audio_sentiment_analysis.py