介绍
# Alexa CLI
使用 `alexacli` 通过非官方 Alexa API 控制 Amazon Echo 设备和智能家居。
## 身份验证
```bash # Browser login (recommended) alexacli auth
# Non-US accounts alexacli auth --domain amazon.de alexacli auth --domain amazon.co.uk
# Check auth status alexacli auth status alexacli auth status --verify # validate token against API
# Remove credentials alexacli auth logout ```
令牌有效期约为 14 天。配置存储在 `~/.alexa-cli/config.json` 中。
## 设备
```bash alexacli devices alexacli devices --json ```
## 文本转语音
```bash # Speak on a specific device alexacli speak "Hello world" -d "Kitchen Echo"
# Announce to ALL devices alexacli speak "Dinner is ready!" --announce
# Device name matching is flexible alexacli speak "Build complete" -d Kitchen ```
## 语音命令(智能家居控制)
发送任意命令,就像您对 Alexa 说出它们一样:
```bash # Lights, switches, plugs alexacli command "turn off the living room lights" -d Kitchen alexacli command "dim the bedroom lights to 50 percent" -d Bedroom
# Thermostats alexacli command "set thermostat to 72 degrees" -d Bedroom alexacli command "what's the temperature inside" -d Kitchen
# Locks alexacli command "lock the front door" -d Kitchen
# Music alexacli command "play jazz music" -d "Living Room" alexacli command "stop" -d "Living Room"
# Questions alexacli command "what's the weather" -d Kitchen
# Timers alexacli command "set a timer for 10 minutes" -d Kitchen ```
## 询问(获取回复)
发送命令并捕获 Alexa 的文本回复:
```bash alexacli ask "what's the thermostat set to" -d Kitchen # Output: The thermostat is set to 68 degrees.
alexacli ask "what's on my calendar today" -d Kitchen --json ```
## Alexa+(LLM 对话)
与亚马逊 LLM 驱动的助手交互:
```bash # Quick start - auto-selects conversation alexacli askplus -d "Echo Show" "What's the capital of France?"
# Multi-turn retains context alexacli askplus -d "Echo Show" "What about Germany?"
# List conversations alexacli conversations
# View conversation history alexacli fragments "amzn1.conversation.xxx" ```
## 音频播放
通过 Echo 设备播放 MP3 音频:
```bash alexacli play --url "https://example.com/audio.mp3" -d "Echo Show" ```
要求:MP3 比特率为 48kbps,采样率为 22050Hz,URL 必须为 HTTPS。
## 历史记录
```bash alexacli history alexacli history --limit 5 alexacli history --json ```
## 命令参考
| 命令 | 描述 | |---------|-------------| | `alexacli devices` | 列出所有 Echo 设备 | | `alexacli speak <text> -d <device>` | 在设备上进行文本转语音 | | `alexacli speak <text> --announce` | 向所有设备广播 | | `alexacli command <text> -d <device>` | 语音命令(智能家居、音乐等) | | `alexacli ask <text> -d <device>` | 发送命令并获取回复 | | `alexacli conversations` | 列出 Alexa+ 对话 ID | | `alexacli fragments <id>` | 查看 Alexa+ 对话历史 | | `alexacli askplus -d <device> <text>` | Alexa+ LLM 对话 | | `alexacli play --url <url> -d <device>` | 通过 SSML 播放 MP3 | | `alexacli auth` | 浏览器登录或手动令牌 | | `alexacli auth status [--verify]` | 显示身份验证状态 | | `alexacli auth logout` | 移除凭据 | | `alexacli history` | 查看最近的语音活动 |
## 注意事项
- 使用亚马逊非官方 API(与 Alexa 应用相同) - 刷新令牌有效期约为 14 天,如果过期请重新运行 `alexacli auth` - 设备名称支持部分匹配,且不区分大小写 - 对于 AI/智能体用途,建议使用 `alexacli command` 配合自然语言 - 在任何命令中添加 `--verbose` 或 `-v` 以获取调试输出