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

# 运行 Audio Analytics 容器

> 部署并运行 Audio Analytics 容器,实现设备端 ASR、文本翻译和 TTS。

Qualcomm 的 Audio Analytics 容器通过 REST 和 WebSocket API 对外提供语音识别 (ASR)、
文本翻译 (T2T) 和文本到语音 (TTS) 能力。所有模型完全在 Qualcomm NPU 上以设备端方式
运行。

## 主要特性

* **一个容器提供三项服务**:ASR、文本到文本翻译和 TTS 通过单一 API 对外提供
* **NPU 加速**:Whisper、OpusMT、MeloTTS 和 PiperTTS 模型全部运行在 Qualcomm NPU 上,
  释放 CPU 用于其他任务
* **多语言**:所有三项服务均支持英语、西班牙语和中文;PiperTTS 另可支持德语和意大利语
* **流式支持**:通过 WebSocket 实现实时转写,同时支持基于文件的批量转写
* **OpenAPI / Swagger UI**:交互式 API 文档可在 `http://<device-ip>:8085/docs` 访问

## 支持的模型

| 服务 | 模型 | 语言 | 采样率 |
| - | - | - | - |
| ASR | `whisper-small-quantized` | 英语、西班牙语、中文 | 16000 Hz |
| 翻译 | `opus-en-es`、`opus-es-en`、`opus-en-zh`、`opus-zh-en` | 英语、西班牙语、中文 | 不适用 |
| TTS | `melo-tts-en`、`melo-tts-es`、`melo-tts-zh` | 英语、西班牙语、中文 | 44100 Hz |
| TTS | `piper-tts-en`、`piper-tts-de`、`piper-tts-it` | 英语、德语、意大利语 | 22050 Hz |

以上是当前支持的模型。可分别查询 `/transcriptions/models`、`/translations/models`
和 `/tts/models` 以确认运行时实际加载的模型。

## 部署

以下步骤假定您已完成设备设置([IQ-9075 EVK](https://dragonwingdocs.qualcomm.com/Ubuntu/devices/iq9075-evk/set-up-the-device.md)
或 [IQ-8275 EVK](https://dragonwingdocs.qualcomm.com/Ubuntu/devices/iq8275-evk/set-up-the-device.md))。
完成设备设置后,请按照以下步骤部署并运行 Audio Analytics 容器。

**1. 安装所需软件包**

通过 SSH 连接到设备并安装所需软件包:

```bash theme={null}
sudo apt update
sudo apt install curl unzip docker-compose
```

**2. 配置 Docker**

```bash theme={null}
# Configure Docker group
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
```

**3. 下载模型**

创建模型目录结构,并从 QAI Hub 下载所有模型。

> [accordion] IQ-9075 EVK
>
> ```bash theme={null}
> mkdir -p ~/models/audio/asr ~/models/audio/tts ~/models/audio/translation
> cd ~/models
>
> # ASR — Whisper Small
> curl -L -o whisper_small_quantized.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/whisper_small_quantized/releases/v0.57.0/whisper_small_quantized-voice_ai-w8a16-qualcomm_qcs9075.zip
> unzip -q whisper_small_quantized.zip -d audio/asr && rm whisper_small_quantized.zip
>
> # TTS — MeloTTS (English, Spanish, Chinese)
> curl -L -o melotts_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_en/releases/v0.57.0/melotts_en-voice_ai-mixed_with_float-qualcomm_qcs9075.zip
> unzip -q melotts_en.zip -d audio/tts && rm melotts_en.zip
>
> curl -L -o melotts_es.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_es/releases/v0.57.0/melotts_es-voice_ai-mixed_with_float-qualcomm_qcs9075.zip
> unzip -q melotts_es.zip -d audio/tts && rm melotts_es.zip
>
> curl -L -o melotts_zh.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_zh/releases/v0.57.0/melotts_zh-voice_ai-mixed_with_float-qualcomm_qcs9075.zip
> unzip -q melotts_zh.zip -d audio/tts && rm melotts_zh.zip
>
> # TTS — PiperTTS (English, German, Italian)
> curl -L -o pipertts_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_en/releases/v0.57.0/pipertts_en-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q pipertts_en.zip -d audio/tts && rm pipertts_en.zip
>
> curl -L -o pipertts_de.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_de/releases/v0.57.0/pipertts_de-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q pipertts_de.zip -d audio/tts && rm pipertts_de.zip
>
> curl -L -o pipertts_it.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_it/releases/v0.57.0/pipertts_it-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q pipertts_it.zip -d audio/tts && rm pipertts_it.zip
>
> # Translation — Opus (English ↔ Spanish, English ↔ Chinese)
> curl -L -o opus_mt_en_es.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_en_es/releases/v0.57.0/opus_mt_en_es-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q opus_mt_en_es.zip -d audio/translation && rm opus_mt_en_es.zip
>
> curl -L -o opus_mt_es_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_es_en/releases/v0.57.0/opus_mt_es_en-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q opus_mt_es_en.zip -d audio/translation && rm opus_mt_es_en.zip
>
> curl -L -o opus_mt_en_zh.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_en_zh/releases/v0.57.0/opus_mt_en_zh-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q opus_mt_en_zh.zip -d audio/translation && rm opus_mt_en_zh.zip
>
> curl -L -o opus_mt_zh_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_zh_en/releases/v0.57.0/opus_mt_zh_en-voice_ai-float-qualcomm_qcs9075.zip
> unzip -q opus_mt_zh_en.zip -d audio/translation && rm opus_mt_zh_en.zip
> ```

> [accordion] IQ-8275 EVK
>
> ```bash theme={null}
> mkdir -p ~/models/audio/asr ~/models/audio/tts ~/models/audio/translation
> cd ~/models
>
> # ASR — Whisper Small
> curl -L -o whisper_small_quantized.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/whisper_small_quantized/releases/v0.57.0/whisper_small_quantized-voice_ai-w8a16-qualcomm_qcs8275.zip
> unzip -q whisper_small_quantized.zip -d audio/asr && rm whisper_small_quantized.zip
>
> # TTS — MeloTTS (English, Spanish, Chinese)
> curl -L -o melotts_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_en/releases/v0.57.0/melotts_en-voice_ai-mixed_with_float-qualcomm_qcs8275.zip
> unzip -q melotts_en.zip -d audio/tts && rm melotts_en.zip
>
> curl -L -o melotts_es.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_es/releases/v0.57.0/melotts_es-voice_ai-mixed_with_float-qualcomm_qcs8275.zip
> unzip -q melotts_es.zip -d audio/tts && rm melotts_es.zip
>
> curl -L -o melotts_zh.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/melotts_zh/releases/v0.57.0/melotts_zh-voice_ai-mixed_with_float-qualcomm_qcs8275.zip
> unzip -q melotts_zh.zip -d audio/tts && rm melotts_zh.zip
>
> # TTS — PiperTTS (English, German, Italian)
> curl -L -o pipertts_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_en/releases/v0.57.0/pipertts_en-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q pipertts_en.zip -d audio/tts && rm pipertts_en.zip
>
> curl -L -o pipertts_de.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_de/releases/v0.57.0/pipertts_de-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q pipertts_de.zip -d audio/tts && rm pipertts_de.zip
>
> curl -L -o pipertts_it.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pipertts_it/releases/v0.57.0/pipertts_it-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q pipertts_it.zip -d audio/tts && rm pipertts_it.zip
>
> # Translation — Opus (English ↔ Spanish, English ↔ Chinese)
> curl -L -o opus_mt_en_es.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_en_es/releases/v0.57.0/opus_mt_en_es-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q opus_mt_en_es.zip -d audio/translation && rm opus_mt_en_es.zip
>
> curl -L -o opus_mt_es_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_es_en/releases/v0.57.0/opus_mt_es_en-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q opus_mt_es_en.zip -d audio/translation && rm opus_mt_es_en.zip
>
> curl -L -o opus_mt_en_zh.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_en_zh/releases/v0.57.0/opus_mt_en_zh-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q opus_mt_en_zh.zip -d audio/translation && rm opus_mt_en_zh.zip
>
> curl -L -o opus_mt_zh_en.zip \
>   https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/opus_mt_zh_en/releases/v0.57.0/opus_mt_zh_en-voice_ai-float-qualcomm_qcs8275.zip
> unzip -q opus_mt_zh_en.zip -d audio/translation && rm opus_mt_zh_en.zip
> ```

您的模型目录现在应类似如下结构:

```
~/models/audio/
├── asr/          ← whisper_small_quantized
├── tts/          ← melotts_en, melotts_es, melotts_zh, pipertts_en, pipertts_de, pipertts_it
└── translation/  ← opus_mt_en_es, opus_mt_es_en, opus_mt_en_zh, opus_mt_zh_en
```

**4. 获取 Docker Compose 文件**

从 [CodeLinaro audio-analytics deploy 目录](https://git.codelinaro.org/clo/iot-solutions-microservices/audio-analytics/-/tree/main/deploy)
下载适合您设备的 Docker Compose 文件。

> [accordion] IQ-9075 EVK
>
> **方案 A —— 直接在设备上下载:**
>
> ```bash theme={null}
> curl -L -o docker-compose-qcs9100.yml \
>   https://git.codelinaro.org/clo/iot-solutions-microservices/audio-analytics/-/raw/main/deploy/docker-compose-qcs9100.yml
> ```
>
> **方案 B —— 在本地下载并复制到设备:**
>
> ```bash theme={null}
> scp docker-compose-qcs9100.yml ubuntu@<device-ip>:~/
> ```

> [accordion] IQ-8275 EVK
>
> **方案 A —— 直接在设备上下载:**
>
> ```bash theme={null}
> curl -L -o docker-compose-qcs8300.yml \
>   https://git.codelinaro.org/clo/iot-solutions-microservices/audio-analytics/-/raw/main/deploy/docker-compose-qcs8300.yml
> ```
>
> **方案 B —— 在本地下载并复制到设备:**
>
> ```bash theme={null}
> scp docker-compose-qcs8300.yml ubuntu@<device-ip>:~/
> ```

> [!NOTE]
>
> 后续步骤均使用 `docker-compose-qcs9100.yml`。如果您使用的是 IQ-8275 EVK,请在每条命令中替换为 `docker-compose-qcs8300.yml`。

**5. 配置容器**

打开 Docker Compose 文件,按需调整以下环境变量:

* **`MODELS_DIR`**:容器内所有模型的基路径(默认:`/mnt/work/models`)
* **`SESSION_TIMEOUT_S`**:ASR 流式会话在空闲多少秒后自动关闭(默认:`30`)
* **`LOG_LEVEL`**:`10`=DEBUG,`20`=INFO,`30`=WARNING,`40`=ERROR(默认:`20`)

在 `volumes:` 下:

* **模型路径**:默认将主机上的 `~/models/audio` 映射到容器中的 `/mnt/work/models`。
  如果您将模型放在其他位置,请更新卷挂载的左侧:

```yaml theme={null}
volumes:
  - ~/models/audio:/mnt/work/models:ro
```

> [!WARNING]
>
> 请确认卷挂载指向您的模型目录,并且该目录可被容器读取。如果模型加载失败,请通过 `ls -la ~/models/audio` 检查目录权限。

**6. 启动容器**

如果尚未存在容器镜像,Docker Compose 文件会自动拉取。

```bash theme={null}
docker compose -f docker-compose-qcs9100.yml up -d
```

确认容器正在运行:

```bash theme={null}
docker ps | grep audio-analytics
```

**7. 验证服务是否正常运行**

容器就绪后,检查 health 端点:

```bash theme={null}
curl http://localhost:8085/audio-analytics/v1/api/health
```

预期响应:

```json theme={null}
{ "status": "ok", "uptime": 12345, "active_sessions": 0, "version": "1.0.0" }
```

您也可以确认加载了哪些模型:

```bash theme={null}
curl http://localhost:8085/audio-analytics/v1/api/transcriptions/models
curl http://localhost:8085/audio-analytics/v1/api/translations/models
curl http://localhost:8085/audio-analytics/v1/api/tts/models
```

**8. 测试每项服务**

对三项服务分别进行一次快速冒烟测试。

**ASR —— 转写音频:**

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/transcriptions/create \
  -F 'file=@audio.wav' \
  -F 'model=whisper-small-quantized' \
  -F 'language=en' \
  -F 'stream=false'
```

预期响应:

```json theme={null}
{ "text": "Your transcribed text here.", "language": "en", "type": "transcript.text.done" }
```

**翻译 —— 翻译文本:**

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/translations/translate \
  -H 'Content-Type: application/json' \
  -d '{"text": ["Hello world"], "model": "opus-en-es", "source_language": "en", "target_language": "es"}'
```

预期响应:

```json theme={null}
{ "translations": [{ "translated_text": "Hola mundo", "source_language": "en", "target_language": "es" }] }
```

**TTS —— 合成语音:**

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/tts/synthesize \
-H 'Content-Type: application/json' \
-d '{"text": "Hello, how are you today?", "model": "melo-tts-en", "language": "en", "sample_rate": 44100}' \
--output speech.pcm
```

**9. 停止容器**

完成后:

```bash theme={null}
docker compose -f docker-compose-qcs9100.yml down
```

## 查看日志

所有容器输出都可通过 `docker logs` 查看,不存在单独的日志文件。

```bash theme={null}
# Stream all logs
docker logs audio-analytics -f -t
```

若要调整日志详细程度,请在 Docker Compose 文件中设置 `LOG_LEVEL` 并重启容器:

| 值 | 级别 |
| - | - |
| `10` | DEBUG |
| `20` | INFO(默认) |
| `30` | WARNING |
| `40` | ERROR |

## 下一步

> [card] [语音识别](https://dragonwingdocs.qualcomm.com/zh/AI-Developer-Workflow-Ubuntu/topic/asr-container.md)
>
> 基于文件和实时流式的转写

> [card] [文本到语音](https://dragonwingdocs.qualcomm.com/zh/AI-Developer-Workflow-Ubuntu/topic/tts-container.md)
>
> 以多种语言合成自然语音

> [card] [语言翻译](https://dragonwingdocs.qualcomm.com/zh/AI-Developer-Workflow-Ubuntu/topic/language-translation.md)
>
> 在设备端在不同语言之间进行文本翻译
