Files
webUI/测试数据快速生成命令.md
2025-12-06 22:42:05 +08:00

169 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🚀 测试数据快速生成命令
## 一键生成(最快方式)
### 方式1: 从现有音频转换
```bash
# 假设你有一个 input.mp3 文件
ffmpeg -i input.mp3 -f s16le -acodec pcm_s16le -ar 16000 -ac 1 test.pcm
# 转为base64一行无换行
base64 test.pcm | tr -d '\n' > test_base64.txt
# 复制 test_base64.txt 的内容,粘贴到 config.js 的 testAudioBase64
```
### 方式2: 快速录音Mac
```bash
# 录制3秒音频并自动转换
rec -r 16000 -c 1 -b 16 test.pcm trim 0 3
# 转为base64
base64 test.pcm | tr -d '\n' > test_base64.txt
```
### 方式3: 生成测试音频Python
```python
# 保存为 generate_test.py
import struct
import base64
sample_rate = 16000
duration = 3
data = bytearray()
for i in range(sample_rate * duration):
# 简单正弦波
import math
sample = int(8000 * math.sin(2 * math.pi * 200 * i / sample_rate))
data.extend(struct.pack('<h', sample))
# 保存PCM
with open('test.pcm', 'wb') as f:
f.write(data)
# 输出base64
b64 = base64.b64encode(data).decode()
print(f"生成完成!大小: {len(data)} bytes")
print(f"Base64长度: {len(b64)} 字符")
print(f"\n请复制以下内容到 config.js:")
print(f"testAudioBase64: '{b64[:100]}...(太长已截断请从test_base64.txt读取)'")
with open('test_base64.txt', 'w') as f:
f.write(b64)
```
运行:
```bash
python generate_test.py
```
## 配置到项目
### 打开配置文件
```bash
# 打开编辑器
code webUI/src/utils/config.js
# 或
vim webUI/src/utils/config.js
```
### 填入数据
```javascript
TEST_MODE: {
enabled: true,
// 方式A: 粘贴base64适合小文件<200KB
testAudioBase64: '此处粘贴你的base64字符串',
// 方式B: 使用文件路径(适合大文件)
testAudioPath: '/static/test_audio.pcm',
}
```
## 验证数据
### 播放测试PCM
```bash
# Mac/Linux
ffplay -f s16le -ar 16000 -ac 1 test.pcm
# 或使用aplay (Linux)
aplay -f S16_LE -r 16000 -c 1 test.pcm
```
### 检查大小
```bash
# 应该接近: 时长(秒) × 32000 bytes
ls -lh test.pcm
```
## 格式速查
```
格式: PCM
采样率: 16000 Hz
位深度: 16 bit (Signed)
声道: 1 (Mono)
字节序: Little Endian
公式: 时长(秒) × 32000 = 文件大小(bytes)
```
## 示例:完整流程
```bash
# 1. 录制或转换音频
ffmpeg -i my_voice.mp3 -f s16le -acodec pcm_s16le -ar 16000 -ac 1 test.pcm
# 2. 验证(能听到声音就对了)
ffplay -f s16le -ar 16000 -ac 1 test.pcm
# 3. 转base64无换行
base64 test.pcm | tr -d '\n' > test_base64.txt
# 4. 复制内容
cat test_base64.txt | pbcopy # Mac
# 或手动打开 test_base64.txt 复制
# 5. 粘贴到 config.js
# testAudioBase64: '刚才复制的内容'
# 完成!
```
## Windows 用户
### 使用 PowerShell
```powershell
# 转base64
$bytes = [System.IO.File]::ReadAllBytes("test.pcm")
$base64 = [System.Convert]::ToBase64String($bytes)
$base64 | Out-File -Encoding ascii test_base64.txt
# 打开查看
notepad test_base64.txt
```
## 快速测试内容建议
录制这些内容任选一个3秒即可
- "你好"
- "今天天气怎么样"
- "给我讲个笑话"
- "帮我查询一下"
- 随便说点什么
---
**准备好后**,在项目中点击 🎧 进入语音模式,然后点击 "🧪 发送测试音频" 按钮测试!