Skip to content

D-Robotics/speech_agent_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

soeech_agent_test

SSH 到 RDK 启动 TTS / Audio / ASR / LLM 服务进行自动化测试。

环境要求

本地 PC

依赖 版本/说明 安装方式
Python 3.12+ apt install python3pyenv
sshpass 任意版本 sudo apt install sshpass
Allure CLI 3.x(可选) npm install -g allure-commandline

Python 包:

pip install -r requirements.txt

RDK 设备(远端)

依赖 说明
TROS Humble ROS2 发行版,安装于 /opt/tros/humble/
speech_agent TTS / Audio / ASR 服务节点
hobot_llamacpp LLM 推理引擎(Qwen2.5-0.5B GGUF)
arecord / aplay ALSA 录音/播音工具(系统自带)
amixer ALSA 音量控制(系统自带)

设备需在 config/device.yaml 中配置 SSH 连接信息(host / username / password)。

配置文件

device.yaml

设备 SSH 连接配置,--device 参数直接对应此文件中的 key。

字段 说明
host 设备 IP 地址
port SSH 端口,默认 22
username SSH 用户名
password SSH 密码
description 设备描述(仅注释用途)
devices:
  X5:
    host: "10.112.133.31"
    port: 22
    username: "root"
    password: "root"
    description: "RDK 开发板 X5"
  X5_Module:
    host: "10.112.133.31"
    port: 22
    username: "root"
    password: "root"
    description: "RDK 开发板 X5 Module"

可通过 utils/ssh_client.pyload_device(name) 函数加载设备配置。

paths.yaml

RDK 设备上的远端路径映射,所有路径均以 rdk: 为根 key。

字段 默认值 说明
wav /root/wav 录音文件存放目录
tts /root/speech_agent/speech_agent_tts TTS 服务源码目录
audio /root/speech_agent/speech_agent_audio Audio 服务源码目录
asr /root/speech_agent/speech_agent_asr ASR 服务源码目录
llm /root/speech_agent/hobot_llamacpp LLM 推理引擎目录
ros_setup /opt/tros/humble/setup.bash ROS2 环境 setup 脚本
gguf /root/speech_agent/hobot_llamacpp/qwen2.5-0.5b-instruct-q4_0.gguf GGUF 模型文件路径

通过 utils/path_util.py 加载,{字段名} 占位符可在 commands.yaml 中引用。

commands.yaml

SSH 远端命令模板,支持 {path_key} 占位符替换为 paths.yaml 中的对应值。

命令 key 用途
tts launch 启动 TTS 服务,支持 {topic} 占位符指定 ROS2 topic
audio launch_4mic 启动 Audio 服务(4mic 模式)
audio launch_6mic 启动 Audio 服务(6mic 模式,mic_type:=6mic
asr launch 启动 ASR 服务
asr launch_llm 启动 ASR 服务(LLM 模式,topic 改为 /prompt_text
llm launch 启动 LLM 推理引擎(hobot_llamacpp),挂载 GGUF 模型
record record arecord 录音命令,{file} 为目标文件名
record play aplay 播放命令,{file} 为播放文件路径
record loopback_play loopback 模式的播放端
record loopback_record loopback 模式的录音端

所有命令模板形如:

tts:
  launch: "cd {tts} && source install/setup.bash && ros2 launch speech_agent_tts speech_agent_tts.launch.py playback_device:=plughw:0,0 topic_sub:={topic}"

tts_texts.yaml

TTS 测试用文本列表,speech_tts_launch.py 按顺序逐条发布到 ROS2 topic。

texts:
  - "你好,世界"
  - "hello world"
  - "1+1=2"
  - "今儿花1分钟,认识狗界宝藏中华十大田园犬..."

每条文本独立发布,日志中会记录合成延迟与发布延迟。

项目结构

├── main.py                          # 入口:依次运行测试脚本
├── requirements.txt
├── config/
│   ├── device.yaml                  # SSH 设备配置
│   ├── paths.yaml                   # 远端路径
│   ├── commands.yaml                # SSH 命令模板
│   └── tts_texts.yaml               # TTS 发布文本
├── utils/
│   ├── ssh_client.py                # load_device / scp_pull
│   ├── path_util.py                 # 路径 & 命令
│   ├── launch_util.py               # SSHSession / make_logger / script_logger
│   └── monitor.py                   # 远端 top 性能采样
├── scripts/
│   ├── analyze_log.py               # 日志解析器 (TTS/Audio/ASR/LLM)
│   ├── speech_tts_launch.py         # TTS 模块测试
│   ├── speech_audio_launch.py       # Audio 模块测试(唤醒词/命令词)
│   ├── speech_asr_launch.py         # ASR 模块测试(语音识别)
│   ├── speech_llm_launch.py         # 全链路测试 (TTS+Audio+ASR+LLM)
│   ├── speech_record_play.py        # 录音/播音/音量/loopback
│   ├── generate_report.py           # 从已有数据生成 Allure 报告
│   ├── report_server.py             # 报告-端口映射管理(多报告多端口服务)
│   └── kill_all.py                  # 远端杀进程
├── log/   table/   wav/   reports/  # gitignore

数据目录结构:

log/<device>/                       table/<device>/
├── tts/                            ├── tts/
├── 4mic/                           ├── 4mic/
│   ├── audio/                      │   ├── audio/
│   ├── asr/                        │   ├── asr/
│   └── llm/                        │   └── llm/
├── 6mic/                           ├── 6mic/
│   ├── audio/                      │   ├── audio/
│   ├── asr/                        │   ├── asr/
│   └── llm/                        │   └── llm/
└── record/                         └── (record 无表格)
    ├── 4mic/
    └── 6mic/

<device>--device 参数值(如 X5),按设备隔离数据。

参数参考

main.py

参数 类型 默认值 说明
--device str X5 设备名,对应 config/device.yaml 中的 key
--mic int 4 麦克风类型:46
--filter str 过滤模块:TTS / Audio / ASR / LLM(大小写不敏感)

speech_tts_launch.py

参数 类型 默认值 说明
--device str X5 设备名
--topic str /tts_text ROS2 topic
--loop int 1 文本发布循环次数
--tts-timeout int 30 单条 TTS 超时秒数
--startup-wait int 3 launch 启动后等待秒数

speech_audio_launch.py

参数 类型 默认值 说明
--device str X5 设备名
--mic int 4 麦克风类型:46

speech_asr_launch.py

参数 类型 默认值 说明
--device str X5 设备名
--mic int 4 麦克风类型:46

speech_llm_launch.py

参数 类型 默认值 说明
--device str X5 设备名
--mic int 4 麦克风类型:46

speech_record_play.py

子命令 参数 说明
record [name] --device 录音(可选文件名)
play <wav> --device, --volume 播放远端 wav 文件
loopback <play_file> [rec_name] --device, --volume 边录边播
pull [file] --device 拉取 wav 到本地
volume --get --device 查看当前 DAC 音量
volume --set <percent> --device 设置 DAC 音量 (0-100)

generate_report.py

参数 说明
--filter <module> 过滤模块(如 tts / asr / llm
--serve [path] 后台挂起 Allure 报告(默认最新)
--list 列出所有报告

report_server.py

命令 说明
list 列出所有可用报告(时间戳 + 测试结果数)
serve [report] 启动报告服务,默认最新,自动分配空闲端口
serve [report] --port N 指定端口启动
status 查看当前所有 报告→端口 映射
stop [port] 停止指定端口,不指定则停止全部

运行测试

# 全部模块(默认 X5 + 4mic)
python3 main.py

# 指定设备和麦克风
python3 main.py --device X5_Module --mic 6

# 只跑指定模块
python3 main.py --filter "Audio"
python3 main.py --filter "LLM"

main.py 只运行测试并输出终端汇总,不生成报告

生成报告

# 基于 /log /table 生成报告
python3 scripts/generate_report.py

# 生成并后台挂起(http://<host>:8080)
python3 scripts/generate_report.py --serve

# 只生成指定模块
python3 scripts/generate_report.py --filter asr

# 打开指定报告
python3 scripts/generate_report.py --serve reports/20260709_120000/allure-results

# 列出所有报告
python3 scripts/generate_report.py --list

每次生成创建独立目录 reports/<ts>/allure-results/,旧报告保留不覆盖。--serve 会先用 allure generate 生成静态 HTML,再用 Python HTTP 服务器挂后台。

关闭后台报告:

kill -9 $(lsof -ti :8080)

report_server.py(多报告多端口)

generate_report.py --serve 只支持单端口 8080。report_server.py 支持同时服务多个报告在不同端口,并提供端口映射管理。

# 列出所有报告
python3 scripts/report_server.py list

# 打开最新报告(自动分配空闲端口,从 8080 递增)
python3 scripts/report_server.py serve

# 打开指定报告
python3 scripts/report_server.py serve 20260709_120000

# 指定端口
python3 scripts/report_server.py serve 20260709_120000 --port 8081

# 查看当前所有报告-端口映射
python3 scripts/report_server.py status

# 停止指定端口
python3 scripts/report_server.py stop 8080

# 停止所有
python3 scripts/report_server.py stop

映射关系持久化到 .report_server_state.jsonstatus 会自动检测并清理已死进程的 stale 记录。

单脚本

# TTS
python3 scripts/speech_tts_launch.py --device X5
python3 scripts/speech_tts_launch.py --loop 3

# Audio
python3 scripts/speech_audio_launch.py --device X5
python3 scripts/speech_audio_launch.py --mic 6

# ASR
python3 scripts/speech_asr_launch.py --device X5 --mic 6

# LLM(全链路)
python3 scripts/speech_llm_launch.py --device X5 --mic 6

# 录音 / 播音 / 音量
python3 scripts/speech_record_play.py record
python3 scripts/speech_record_play.py play /root/wav/xxx.wav
python3 scripts/speech_record_play.py play /root/wav/xxx.wav --volume 50
python3 scripts/speech_record_play.py loopback /root/wav/xxx.wav my.wav --volume 50
python3 scripts/speech_record_play.py pull
python3 scripts/speech_record_play.py volume --set 50
python3 scripts/speech_record_play.py volume --get

测试指标

模块 成功标志 数据内容
TTS sa_tts_create success 合成延迟、发布延迟、性能数据
Audio /wkp_text 话题出现 唤醒/命令词事件、DOA、性能数据
ASR asr init success 识别会话、延迟、性能数据
LLM generate: ASR 会话 + LLM 问答对、性能数据

其他工具

python3 scripts/kill_all.py   # 强杀远端所有 speech_agent / hobot_llamacpp 进程

About

A test script for the speech_agent that integrates module testing and generates reports.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages