Audio Sentiment Analysis

Demonstrates team-based transcription and sentiment analysis for audio conversations.

audio_sentiment_analysis.py
"""
Audio Sentiment Analysis
========================

Demonstrates team-based transcription and sentiment analysis for audio conversations.
"""

import requests
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.media import Audio
from agno.models.google import Gemini
from agno.team import Team

# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
transcription_agent = Agent(
    name="Audio Transcriber",
    role="Transcribe audio conversations accurately",
    model=Gemini(id="gemini-3.5-flash"),
    instructions=[
        "Transcribe audio with speaker identification",
        "Maintain conversation structure and flow",
    ],
)

sentiment_analyst = Agent(
    name="Sentiment Analyst",
    role="Analyze emotional tone and sentiment in conversations",
    model=Gemini(id="gemini-3.5-flash"),
    instructions=[
        "Analyze sentiment for each speaker separately",
        "Identify emotional patterns and conversation dynamics",
        "Provide detailed sentiment insights",
    ],
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
sentiment_team = Team(
    name="Audio Sentiment Team",
    members=[transcription_agent, sentiment_analyst],
    model=Gemini(id="gemini-3.5-flash"),
    instructions=[
        "Analyze audio sentiment with conversation memory.",
        "Audio Transcriber: First transcribe audio with speaker identification.",
        "Sentiment Analyst: Analyze emotional tone and conversation dynamics.",
    ],
    add_history_to_context=True,
    markdown=True,
    db=SqliteDb(
        session_table="audio_sentiment_team_sessions",
        db_file="tmp/audio_sentiment_team.db",
    ),
)

# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    url = "https://agno-public.s3.amazonaws.com/demo_data/sample_conversation.wav"
    response = requests.get(url)
    audio_content = response.content

    sentiment_team.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,
    )

    sentiment_team.print_response(
        "What else can you tell me about this audio conversation?",
        stream=True,
    )

Before running

The downloaded sample is WAV. Replace Audio(content=audio_content) with Audio(content=audio_content, mime_type="audio/wav"); Gemini otherwise labels untyped audio bytes with its MP3 default. Add response.raise_for_status() after downloading so an error body is not passed as audio. The second call uses the same in-process session; use an explicit session_id to continue it after restarting the script. Speaker labels and sentiment are model interpretations.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno google-genai requests sqlalchemy

Export 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.py

Full source: cookbook/03_teams/19_multimodal/audio_sentiment_analysis.py