> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 博客转播客代理

## 代码

```python theme={null}
import os
from uuid import uuid4
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.eleven_labs import ElevenLabsTools
from agno.tools.firecrawl import FirecrawlTools
from agno.agent import Agent, RunResponse
from agno.utils.audio import write_audio_to_file
from agno.utils.log import logger


url = "https://www.bcg.com/capabilities/artificial-intelligence/ai-agents"

blog_to_podcast_agent = Agent(
    name="博客转播客代理",
    agent_id="blog_to_podcast_agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[
        ElevenLabsTools(
            voice_id="JBFqnCBsd6RMkjVDRZzb",
            model_id="eleven_multilingual_v2",
            target_directory="audio_generations",
        ),
        FirecrawlTools(),
    ],
    description="你是一个可以使用 ElevenLabs API 生成音频的 AI 代理。",
    instructions=[
        "当用户提供博客网址时：",
        "1. 使用 FirecrawlTools 抓取博客内容",
        "2. 创建博客内容的简洁摘要，长度不超过 2000 个字符",
        "3. 摘要应包含要点，同时具有吸引力和对话性",
        "4. 使用 ElevenLabsTools 将摘要转换为音频",
        "你不需要先找到合适的语音，我已经为用户指定了语音",
        "确保摘要在 2000 个字符的限制内，以避免 ElevenLabs API 的限制",
    ],
    markdown=True,
    debug_mode=True,
)

podcast: RunResponse = blog_to_podcast_agent.run(
    f"将博客内容转换为播客：{url}"
)

save_dir = "audio_generations"

if podcast.audio is not None and len(podcast.audio) > 0:
    try:
        os.makedirs(save_dir, exist_ok=True)
        filename = f"{save_dir}/sample_podcast{uuid4()}.wav"
        write_audio_to_file(
            audio=podcast.audio[0].base64_audio,
            filename=filename
        )
        print(f"音频已成功保存到：{filename}")
    except Exception as e:
        print(f"保存音频文件时出错：{e}")
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="设置您的 API 密钥">
    ```bash theme={null}
    export OPENAI_API_KEY=xxx
    export ELEVEN_LABS_API_KEY=xxx
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U openai elevenlabs firecrawl-py agno
    ```
  </Step>

  <Step title="运行代理">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/multimodal/blog_to_podcast.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/multimodal/blog_to_podcast.py
      ```
    </CodeGroup>
  </Step>
</Steps>
