Ai_GirlFriend/测试音乐库唱歌功能.md
2026-02-04 18:47:56 +08:00

122 lines
2.8 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.

# 测试音乐库唱歌功能
## ✅ 修复完成
前端代码已修复API 参数传递问题已解决。
---
## 🧪 测试步骤
### 1. 启动后端服务
双击运行:`启动后端服务.bat`
等待看到:
```
INFO: Uvicorn running on http://0.0.0.0:30101
INFO: Application startup complete.
```
### 2. 验证 API
打开浏览器访问http://localhost:30101/docs
找到 `POST /music/convert-to-song`,应该能看到:
- 参数:`music_id` (query, required, integer)
### 3. 重新编译前端
保存 `xuniYou/pages/index/index.vue` 后,重新编译前端项目。
### 4. 测试功能
#### 测试场景 1直链音乐应该成功
1. 打开应用,进入音乐库
2. 点击任意 Bensound 音乐(直链音乐)
3. 应该弹出确认框:"确定让她唱《xxx》吗"
4. 点击"确定"
5. 应该显示"准备中..." → "生成中..."
6. 生成完成后自动切换到"历史记录" tab
7. 视频自动播放
#### 测试场景 2外部链接音乐应该提示
1. 点击外部平台音乐网易云、QQ音乐
2. 应该弹出提示:"外部平台音乐无法生成视频,请使用直链或上传的音乐"
#### 测试场景 3重复生成应该使用缓存
1. 再次点击相同的音乐
2. 应该立即成功(不需要等待生成)
3. 直接显示"生成成功"并播放视频
---
## 🐛 已修复的问题
### 问题API 参数传递错误
**错误日志**
```
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'missing', 'loc': ('query', 'music_id'), 'msg': 'Field required', 'input': None}
```
**原因**
- 后端定义:`music_id: int`query 参数)
- 前端发送:`data: { music_id: music.id }`body 参数)
**解决**
修改前端为:`url: baseURLPy + '/music/convert-to-song?music_id=' + music.id`
---
## 📊 预期结果
### 成功的请求日志
```
INFO: POST /music/convert-to-song?music_id=1 HTTP/1.1" 200 OK
INFO: POST /sing/generate HTTP/1.1" 200 OK
```
### 成功的响应
```json
{
"code": 1,
"message": "success",
"data": {
"song_id": 123,
"status": "succeeded",
"video_url": "https://..."
}
}
```
---
## 🔍 调试技巧
### 查看后端日志
后端服务会输出详细日志,包括:
- 请求 URL 和参数
- 数据库查询
- 错误信息
### 查看前端日志
按 F12 打开浏览器开发者工具:
- **Console** 标签:查看 JavaScript 错误
- **Network** 标签:查看 API 请求和响应
### 常见问题
1. **422 错误**:参数传递错误(已修复)
2. **401 错误**TOKEN 过期,需要重新登录
3. **404 错误**API 路径错误或后端服务未启动
4. **500 错误**:后端服务异常,查看后端日志
---
**测试说明版本**: 1.0
**创建时间**: 2026-02-04 18:15
**状态**: ✅ 可以开始测试