Skip to content

Commit 38beb9c

Browse files
authored
Merge pull request #2 from Sakura-RanChen/main
update: Dockerfile docker测试正常
2 parents 0855caa + 8827331 commit 38beb9c

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 第一阶段:构建Python依赖
2+
FROM python:3.10-slim AS builder
3+
4+
WORKDIR /app
5+
6+
COPY requirements.txt .
7+
8+
RUN pip install --no-cache-dir -r requirements.txt
9+
10+
# 第二阶段:生产镜像
11+
FROM python:3.10-slim
12+
13+
WORKDIR /app
14+
15+
# 安装系统依赖
16+
RUN apt-get update && \
17+
apt-get install -y --no-install-recommends libopus0 ffmpeg && \
18+
apt-get clean && \
19+
rm -rf /var/lib/apt/lists/*
20+
21+
# 复制Python依赖
22+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
23+
24+
# 复制应用代码
25+
COPY . .
26+
27+
# 创建临时目录
28+
RUN mkdir -p /app/tmp
29+
30+
# 启动应用
31+
CMD ["python", "app.py"]

app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def load_config():
3737

3838
try:
3939
config = load_config()
40-
API_TOKEN = config['server']['token']
40+
API_TOKEN = config['server']['authorization']
4141
except Exception as e:
4242
logger.error(f"配置加载失败: {e}")
4343
raise
@@ -99,7 +99,7 @@ def ensure_16k_wav(audio_bytes):
9999

100100
@app.post("/register", summary="声纹注册")
101101
async def register(
102-
token: str = Header(..., description="接口令牌"),
102+
authorization: str = Header(..., description="接口令牌", alias="authorization"),
103103
speaker_id: str = Form(..., description="说话人ID"),
104104
file: UploadFile = File(..., description="WAV音频文件")
105105
):
@@ -112,7 +112,7 @@ async def register(
112112
返回:
113113
注册结果
114114
"""
115-
check_token(token)
115+
check_token(authorization)
116116
audio_path = None
117117
try:
118118
audio_bytes = await file.read()
@@ -131,7 +131,7 @@ async def register(
131131

132132
@app.post("/identify", summary="声纹识别")
133133
async def identify(
134-
token: str = Header(..., description="接口令牌"),
134+
authorization: str = Header(..., description="接口令牌", alias="authorization"),
135135
speaker_ids: str = Form(..., description="候选说话人ID,逗号分隔"),
136136
file: UploadFile = File(..., description="WAV音频文件")
137137
):
@@ -144,7 +144,7 @@ async def identify(
144144
返回:
145145
识别结果(说话人ID、相似度分数)
146146
"""
147-
check_token(token)
147+
check_token(authorization)
148148
candidate_ids = [x.strip() for x in speaker_ids.split(",") if x.strip()]
149149
if not candidate_ids:
150150
logger.warning("候选说话人ID不能为空。")

test_user.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import requests
22

3-
token = "123456" # 替换为你的真实token
4-
base_url = "http://192.168.4.82:8000"
3+
authorization = "Bearer ac1ab7b959989135c030157ee5b73eb5"
4+
base_url = "http://192.168.81.200:8004"
55

66
# # 注册三个说话人
77
# for i in range(3):
88
# wav_path = f"test/test{i}.wav"
99
# speaker_id = f"user_{i}"
1010
# files = {'file': open(wav_path, 'rb')}
1111
# data = {'speaker_id': speaker_id}
12-
# headers = {'token': token}
12+
# headers = {'authorization': authorization}
1313
# resp = requests.post(f"{base_url}/register", files=files, data=data, headers=headers)
1414
# print(f"注册 {speaker_id}:", resp.json())
1515

1616
# 声纹识别
17-
wav_path = "test/test2.wav"
17+
wav_path = "test/test0.wav"
1818
candidate_ids = "user_0,user_1,user_2"
1919
files = {'file': open(wav_path, 'rb')}
2020
data = {'speaker_ids': candidate_ids}
21-
headers = {'token': token}
21+
headers = {'authorization': authorization}
2222
resp = requests.post(f"{base_url}/identify", files=files, data=data, headers=headers)
2323
print("识别结果:", resp.json())

voiceprint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server:
44
# 服务监听端口
55
port: 8004
66
# 接口访问令牌,调用API时需在header中携带
7-
token: "your_api_token"
7+
authorization: "Bearer ac1ab7b959989135c030157ee5b73eb5"
88

99
mysql:
1010
# MySQL数据库主机地址

0 commit comments

Comments
 (0)