Skip to content

Commit

Permalink
fix: save audio
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragts committed Feb 14, 2025
1 parent 3d01aa6 commit 55ba60c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions cookbook/agent_concepts/multimodal/music_generation_agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models_labs import ModelsLabTools, FileType
from agno.storage.agent.sqlite import SqliteAgentStorage
import os
from uuid import uuid4

import requests
from agno.agent import Agent, RunResponse
from agno.utils.audio import write_audio_to_file
from agno.models.openai import OpenAIChat
from agno.tools.models_labs import FileType, ModelsLabTools
from agno.utils.log import logger

agent = Agent(
name="ModelsLab Music Agent",
Expand All @@ -20,21 +22,21 @@
"- The structure (intro, verses, chorus, bridge, etc.)",
"Create rich, descriptive prompts that capture the desired musical elements.",
"Focus on generating high-quality, complete instrumental pieces.",
"Keep responses simple and only confirm when music is generated successfully.",
"Give the music link in the response",
],
markdown=True,
debug_mode=True,
)

music: RunResponse = agent.run(
"Generate a 30 second classical music piece"
)
if music.response_audio is not None:
write_audio_to_file(
audio=music.response_audio.content, filename="tmp/sample_music.wav"
)
music: RunResponse = agent.run("Generate a 30 second classical music piece")

save_dir = "audio_generations"

# agent.print_response(
# "Generate a 30 second classical music piece"
# )
if music.audio is not None and len(music.audio) > 0:
url = music.audio[0].url
response = requests.get(url)
# Create tmp directory if it doesn't exist
os.makedirs(save_dir, exist_ok=True)
filename = f"{save_dir}/sample_music{uuid4()}.wav"
with open(filename, "wb") as f:
f.write(response.content)
logger.info(f"Music saved to {filename}")

0 comments on commit 55ba60c

Please sign in to comment.