Local-Voice/SYSTEMD_SETUP.md
2025-09-26 13:11:14 +08:00

115 lines
2.8 KiB
Markdown
Raw Permalink 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.

# Local Voice Systemd 服务配置指南
## 问题解决方案
### 核心问题
- **直接运行**: 使用PulseAudio自动转换16000Hz采样率 ✅
- **systemd运行**: 直接访问USB设备只支持48000/44100Hz ❌
### 解决策略
通过配置systemd服务访问用户会话的PulseAudio利用其采样率转换能力。
## 部署步骤
### 1. 上传文件到树莓派
```bash
scp local-voice.service local-voice-user.service deploy-service.sh test-audio.py zhuchaowe@192.168.101.212:~/Local-Voice/
```
### 2. 运行部署脚本
```bash
cd ~/Local-Voice
./deploy-service.sh
```
### 3. 测试音频访问
```bash
python3 test-audio.py
```
### 4. 启动服务 (推荐使用用户级服务)
```bash
# 用户级服务 (推荐)
systemctl --user start local-voice-user.service
systemctl --user enable local-voice-user.service
# 查看日志
journalctl --user -u local-voice-user.service -f
# 如果用户级服务不工作,尝试系统级服务
sudo systemctl start local-voice.service
sudo systemctl enable local-voice.service
# 查看系统服务日志
sudo journalctl -u local-voice.service -f
```
## 服务配置说明
### 系统级服务 (local-voice.service)
- 适用于传统systemd环境
- 添加了PulseAudio环境变量
- 包含音频设备权限
### 用户级服务 (local-voice-user.service)
- 推荐方案,更好的音频访问
- 自动继承用户会话环境
- 无需额外环境变量配置
## 故障排除
### 音频设备不可用
1. 检查pipewire-pulse服务:
```bash
systemctl --user status pipewire-pulse
systemctl --user start pipewire-pulse
```
2. 检查音频设备权限:
```bash
groups # 确认在audio组中
```
3. 测试直接运行:
```bash
python3 multiprocess_recorder.py --enable-nfc
```
### 权限问题
如果遇到权限错误确保用户在audio组中:
```bash
sudo usermod -a -G audio $USER
# 重新登录或重启系统
```
### 环境变量问题
如果用户级服务正常但系统级服务有问题,可能需要:
1. 检查环境变量是否正确设置
2. 确认pipewire-pulse服务在系统启动时运行
3. 考虑使用用户级服务作为主要方案
## 验证步骤
1. **环境测试**: `python3 test-audio.py`
2. **服务启动**: `systemctl --user start local-voice-user.service`
3. **日志监控**: `journalctl --user -u local-voice-user.service -f`
4. **功能测试**: 使用NFC卡片触发录音功能
## 备用方案
如果上述方案不工作,可以考虑:
### 方案A: 使用screen会话
```bash
screen -dmS local-voice python3 ~/Local-Voice/multiprocess_recorder.py --enable-nfc
screen -r local-voice # 查看输出
```
### 方案B: 使用cron启动
在crontab中添加:
```
@reboot cd ~/Local-Voice && python3 multiprocess_recorder.py --enable-nfc
```
### 方案C: 修改代码支持多种采样率
如果需要修改代码支持48000Hz采样率请告知。