SmartMeeting/voice-dected/get_voice_embedding.py

22 lines
700 B
Python
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.

import requests
# 本地 FastAPI 服务地址
url = "http://172.18.127.124:9666/extract_embedding"
# 要上传的 WAV 文件路径
wav_file_path = "/Users/lijinxuan/PycharmProjects/Sea/output1.wav"
# 打开文件并发送 POST 请求
with open(wav_file_path, "rb") as f:
files = {"wav_file": (f.name, f, "audio/wav")}
response = requests.post(url, files=files)
# 检查响应状态
if response.status_code == 200:
result = response.json()
embedding = result["embedding"]
print(f"成功提取 embedding维度: {len(embedding)}")
print("embedding:", embedding)
else:
print(f"请求失败,状态码: {response.status_code}")
print("错误信息:", response.text)