> ## 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.

# Groq

`GroqTools` 允许 Agent 与 Groq API 交互，以执行快速的音频转录、翻译和文本转语音 (TTS)。

## 先决条件

在使用 `GroqTools` 之前，请确保您已安装 `groq` 库并配置了您的 Groq API 密钥。

1. **安装库：**
   ```bash theme={null}
   pip install -U groq
   ```

2. **设置您的 API 密钥：** 从 [Groq 控制台](https://console.groq.com/keys) 获取您的 API 密钥，并将其设置为环境变量。

   <CodeGroup>
     ```bash Mac theme={null}
     export GROQ_API_KEY="your-groq-api-key"
     ```

     ```bash Windows theme={null}
     setx GROQ_API_KEY "your-groq-api-key"
     ```
   </CodeGroup>

## 初始化

导入 `GroqTools` 并将其添加到 Agent 的工具列表中。

```python theme={null}
from agno.agent import Agent
from agno.tools.models.groq import GroqTools

agent = Agent(
    instructions=[
        "You are a helpful assistant that can transcribe audio, translate text and generate speech."
    ],
    tools=[GroqTools()],
    show_tool_calls=True,
)
```

## 使用示例

### 1. 音频转录

此示例演示了如何转录托管在 URL 中的音频文件。

```python transcription_agent.py theme={null}
import os
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.groq import GroqTools

audio_url = "https://agno-public.s3.amazonaws.com/demo_data/sample_conversation.wav"

agent = Agent(
    name="Groq Transcription Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[GroqTools()],
    show_tool_calls=True,
)

agent.print_response(f"Please transcribe the audio file located at '{audio_url}'")
```

### 2. 音频翻译和语音生成

此示例展示了如何将音频文件（例如法语）翻译成英语，然后使用翻译后的文本生成新的音频文件。

```python translation_agent.py theme={null}
from pathlib import Path
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.groq import GroqTools
from agno.utils.media import save_base64_data

local_audio_path = "tmp/sample-fr.mp3"
output_path = Path("tmp/sample-en.mp3")
output_path.parent.mkdir(parents=True, exist_ok=True)

agent = Agent(
    name="Groq Translation Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[GroqTools()],
    show_tool_calls=True,
)

instruction = (
    f"Translate the audio file at '{local_audio_path}' to English. "
    f"Then, generate a new audio file using the translated English text."
)
agent.print_response(instruction)

response = agent.run_response
if response and response.audio:
    save_base64_data(response.audio[0].base64_audio, output_path)
```

您可以在初始化期间自定义用于转录、翻译和 TTS 的底层 Groq 模型：

```python theme={null}
groq_tools = GroqTools(
    transcription_model="whisper-large-v3",
    translation_model="whisper-large-v3",
    tts_model="playai-tts",
    tts_voice="Chip-PlayAI"
)
```

## Toolkit 功能

`GroqTools` toolkit 提供以下功能：

| Function           | Description                              |
| ------------------ | ---------------------------------------- |
| `transcribe_audio` | 使用 Groq Whisper 将本地文件路径或公共 URL 的音频转录成文本。 |
| `translate_audio`  | 使用 Groq 将本地文件路径或公共 URL 的音频翻译成英语。         |
| `generate_speech`  | 使用 Groq TTS 将文本生成语音。                     |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/models/groq.py)
* 查看 [Transcription Example](https://github.com/agno-agi/agno/blob/main/cookbook/models/groq/transcription_agent.py)
* 查看 [Translation Example](https://github.com/agno-agi/agno/blob/main/cookbook/models/groq/translation_agent.py)
