语音音频(wav)声纹识别-技术实现-python

通过pyannote.audio 实现语音音频声纹识别。

安装:

python 复制代码
pip install pyannote.audio

示例音频下载地址:【免费】语音音频(WAV)声纹识别示例资源-CSDN文库

实现代码:

python 复制代码
from pyannote.audio import Model
from pyannote.audio import Inference
from scipy.spatial.distance import cdist
# 初始化模型
model = Model.from_pretrained("pyannote/wespeaker-voxceleb-resnet34-LM",cache_dir = "./ckpt/",local_files_only = False)

inference = Inference(model, window="whole")
# 获取音频的特征
embedding_1 = inference(r"audio_data\0\014.wav").reshape(1,-1) # id 为 0 的人的音频
embedding_2 = inference(r"audio_data\0\021.wav").reshape(1,-1) # id 为 0 的人的音频
embedding_3 = inference(r"audio_data\1\004.wav").reshape(1,-1) # id 为 1 的人的音频

print("embedding_1:",embedding_1.shape)

# 通过余弦相似度,比较音频特征向量间的距离,获取相似度,距离越小,特征越相近,可能为同一人说话的可能性越高。
distance_sim = cdist(embedding_1 , embedding_2 , metric="cosine")[0,0]
distance_not = cdist(embedding_1 , embedding_3 , metric="cosine")[0,0]

# 余弦距离越小越接近
print("相同人 Distance emb1 between emb2: " + str(distance_sim))
print("不同人 Distance emb1 between emb3: " + str(distance_not))

程序运行输出信息如下:

python 复制代码
相同人 Distance emb1 between emb2: 0.447950675466506
不同人 Distance emb1 between emb3: 0.7426738655303657
相关推荐
染指11105 小时前
26.RAG进阶(Advanced RAG)-假设性问题索引
人工智能·windows·agent·rag·advanced rag
闵孚龙5 小时前
动态图机制:为什么 PyTorch 调试起来更舒服
人工智能·pytorch·python
chushiyunen6 小时前
langchain4j笔记、tools
笔记·python·flask
甲维斯6 小时前
还要啥Codex!DeepSeek接入Zcode远程连接!
人工智能
Kobebryant-Manba6 小时前
RNN从0实现
pytorch·rnn·深度学习
百胜软件@百胜软件6 小时前
百胜软件亮相“AI消费新生活”主题日活动,AI智能运营平台入选市级案例征集
人工智能·生活·零售数字化·数智中台·珠宝行业
程序员三藏7 小时前
Web自动化测试详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
在放️7 小时前
Python 爬虫 · 第三方代理接入与合规使用
开发语言·爬虫·python
专注搞钱7 小时前
GPT-4o写设备Recipe:从3小时到10分钟
数据库·人工智能·gpt·半导体
闻道参看8 小时前
贝芯宠AI灵兽 ELFVET 大模型聚焦临床应用,强化宠物诊疗综合能力
人工智能·宠物