当前位置: 首页 > news >正文

用vs做购物网站网络营销与直播电商专升本

用vs做购物网站,网络营销与直播电商专升本,关于网站建设的外文文献,微信网站网址使用pyannote-audio实现声纹分割聚类 # GitHub地址 https://github.com/MasonYyp/audio1 简单介绍 pyannote.audio是用Python编写的用于声纹分割聚类的开源工具包。在PyTorch机器学习基础上,不仅可以借助性能优越的预训练模型和管道实现声纹分割聚类,还…

使用pyannote-audio实现声纹分割聚类

# GitHub地址
https://github.com/MasonYyp/audio

1 简单介绍

pyannote.audio是用Python编写的用于声纹分割聚类的开源工具包。在PyTorch机器学习基础上,不仅可以借助性能优越的预训练模型和管道实现声纹分割聚类,还可以进一步微调模型。

它的主要功能有以下几个:

  1. 声纹嵌入:从一段声音中提出声纹转换为向量(嵌入);
  2. 声纹识别:从一段声音中识别不同的人(多个人);
  3. 声纹活动检测:检测一段声音检测不同时间点的活动;
  4. 声纹重叠检测:检测一段声音中重叠交叉的部分;
  5. 声纹分割;将一段声音进行分割;

pyannote.audio中主要有”segmentation“、”embedding“和”speaker-diarization“三个模型,”segmentation“的主要作用是分割、”embedding“主要作用是嵌入(跟wespeaker-voxceleb-resnet34-LM作用相同),”speaker-diarization“的作用是使用管道对上面两个模型整合。

pyannote-audio的参考地址

# Huggingface地址
https://hf-mirror.com/pyannote# Github地址
https://github.com/pyannote/pyannote-audio

⚠️ 注意: pyannote.audio不同的版本有些区别;

2 使用pyannote.audio:3.1.3

2.1 安装pyannote.audio

pip install pyannote.audio==3.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

使用模型需要现在huggingface上下载模型,模型如下:

⚠️ pyannote.audio的部分模型是收到保护的,即需要在huggingface登录后,填写部分信息,同意相关协议才能下载,否则无法下载。

# 1 嵌入模型 pyannote/wespeaker-voxceleb-resnet34-LM 
https://hf-mirror.com/pyannote/wespeaker-voxceleb-resnet34-LM# 2 分割模型 pyannote/segmentation-3.0
https://hf-mirror.com/pyannote/segmentation-3.0

使用huggingface-cli下载相关模型的命令:

# 注意:需要先创建Python环境# 安装huggingface-cli
pip install -U huggingface_hub# 例如下载pyannote/embedding模型
# 必须提供Hugging上的 --token hf_****
huggingface-cli download --resume-download pyannote/embedding --local-dir pyannote/embedding --local-dir-use-symlinks False --token hf_****

注意两个类

# Inference主要用于声纹嵌入
pyannote.audio import Inference# Annotation主要用于声纹分割
from pyannote.core import Annotation# Annotation中的主要方法,假设实例为;diarization
# 获取声音中说话人的标识
labels = diarization.labels()# 获取声音中全部的活动Segment(列表)
segments = list(diarization.itertracks())# 获取声音中指定说话人时间段(列表),”SPEAKER_00“为第一个说话人的标识
durations = diarization.label_timeline('SPEAKER_00')

2.2 实现声纹分割

注意:pyannote/speaker-diarization-3.1实现声纹识别特别慢,不知道是不是我的方法不对(30分钟的音频,处理了20多分钟)。⚠️ 使用单个模型很快。pyannote/speaker-diarization(版本2)较快,推荐使用pyannote/speaker-diarization(版本2)。

注意:此处加载模型和通常加载模型的思路不同,常规加载模型直接到名称即可,此处需要加载到具体的模型名称。

(1)使用python方法

# 使用 pyannote-audio-3.1.1
import timefrom pyannote.audio import Model
from pyannote.audio.pipelines import SpeakerDiarization
from pyannote.audio.pipelines.utils import PipelineModel
from pyannote.core import Annotation# 语音转向量模型
embedding: PipelineModel = Model.from_pretrained("E:/model/pyannote/pyannote-audio-3.1.1/wespeaker-voxceleb-resnet34-LM/pytorch_model.bin")
# 分割语音模型
segmentation: PipelineModel = Model.from_pretrained("E:/model/pyannote/pyannote-audio-3.1.1/segmentation-3.0/pytorch_model.bin")# 语音分离模型
speaker_diarization: SpeakerDiarization = SpeakerDiarization(segmentation=segmentation, embedding=embedding)# 初始化语音分离模型的参数
HYPER_PARAMETERS = {"clustering": {"method": "centroid","min_cluster_size": 12,"threshold": 0.7045654963945799},"segmentation":{"min_duration_off": 0.58}
}
speaker_diarization.instantiate(HYPER_PARAMETERS)start_time = time.time()# 分离语音
diarization: Annotation = speaker_diarization("E:/语音识别/数据/0-test-en.wav")# 获取说话人列表
print(diarization.labels())
# 获取活动segments列表
print(list(diarization.itertracks()))
print(diarization.label_timeline('SPEAKER_00'))ent_time = time.time()
print(ent_time - start_time)

(2)使用yml方法

# instantiate the pipeline
from pyannote.audio import Pipeline
from pyannote.core import Annotationspeaker_diarization = Pipeline.from_pretrained("E:/model/pyannote/speaker-diarization-3.1/config.yaml")# 分离语音
diarization: Annotation = speaker_diarization("E:/语音识别/数据/0-test-en.wav")print(type(diarization))
print(diarization.labels())

config.yaml

根据文件可以看出,声纹分割是将embedding和segmentation进行了组合。

version: 3.1.0pipeline:name: pyannote.audio.pipelines.SpeakerDiarizationparams:clustering: AgglomerativeClustering# embedding: pyannote/wespeaker-voxceleb-resnet34-LMembedding: E:/model/pyannote/speaker-diarization-3.1/wespeaker-voxceleb-resnet34-LM/pytorch_model.binembedding_batch_size: 32embedding_exclude_overlap: true# segmentation: pyannote/segmentation-3.0segmentation: E:/model/pyannote/speaker-diarization-3.1/segmentation-3.0/pytorch_model.binsegmentation_batch_size: 32params:clustering:method: centroidmin_cluster_size: 12threshold: 0.7045654963945799segmentation:min_duration_off: 0.0

模型目录

模型中的其他文件可以删除,只保留”pytorch_model.bin“即可。

在这里插入图片描述

执行结果

在这里插入图片描述

2.3 实现声纹识别

比较两段声音的相似度。

from pyannote.audio import Model
from pyannote.audio import Inference
from scipy.spatial.distance import cdist# 导入模型
embedding = Model.from_pretrained("E:/model/pyannote/speaker-diarization-3.1/wespeaker-voxceleb-resnet34-LM/pytorch_model.bin")# 抽取声纹
inference: Inference = Inference(embedding, window="whole")# 生成声纹,1维向量
embedding1 = inference("E:/语音识别/数据/0-test-en.wav")
embedding2 = inference("E:/语音识别/数据/0-test-en.wav")# 计算两个声纹的相似度
distance = cdist([embedding1], [embedding2], metric="cosine")
print(distance)

2.4 检测声纹活动


from pyannote.audio import Model
from pyannote.core import Annotation
from pyannote.audio.pipelines import VoiceActivityDetection# 加载模型
model = Model.from_pretrained("E:/model/pyannote/speaker-diarization-3.1/segmentation-3.0/pytorch_model.bin")# 初始化参数
activity_detection = VoiceActivityDetection(segmentation=model)
HYPER_PARAMETERS = {# remove speech regions shorter than that many seconds."min_duration_on": 1,# fill non-speech regions shorter than that many seconds."min_duration_off": 0
}
activity_detection.instantiate(HYPER_PARAMETERS)# 获取活动特征
annotation: Annotation = activity_detection("E:/语音识别/数据/0-test-en.wav")# 获取活动列表
segments = list(annotation.itertracks())
print(segments)

3 使用pyannote.audio:2.1.1

⚠️ 推荐使用此版本

3.1 安装pyannote.audio

# 安装包
pip install pyannote.audio==2.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple# 1 嵌入模型 pyannote/embedding
https://hf-mirror.com/pyannote/embedding# 2 分割模型 pyannote/segmentation
https://hf-mirror.com/pyannote/segmentation

3.2 实现声纹分割

# 使用 pyannote-audio-2.1.1
import timefrom pyannote.audio.pipelines import SpeakerDiarization
from pyannote.audio import Model
from pyannote.audio.pipelines.utils import PipelineModel
from pyannote.core import Annotation# 语音转向量模型
embedding: PipelineModel = Model.from_pretrained("E:/model/pyannote/pyannote-audio-2.1.1/embedding/pytorch_model.bin")# 分割语音模型
segmentation: PipelineModel = Model.from_pretrained("E:/model/pyannote/pyannote-audio-2.1.1/segmentation/pytorch_model.bin")# 语音分离模型
speaker_diarization: SpeakerDiarization = SpeakerDiarization(segmentation=segmentation,embedding=embedding,clustering="AgglomerativeClustering"
)HYPER_PARAMETERS = {"clustering": {"method": "centroid","min_cluster_size": 15,"threshold": 0.7153814381597874},"segmentation":{"min_duration_off": 0.5817029604921046,"threshold": 0.4442333667381752}
}speaker_diarization.instantiate(HYPER_PARAMETERS)start_time = time.time()
# vad: Annotation = pipeline("E:/语音识别/数据/0-test-en.wav")
diarization: Annotation = speaker_diarization("E:/语音识别/数据/0-test-en.wav")# 获取说话人列表
print(diarization.labels())ent_time = time.time()
print(ent_time - start_time)

3.3 其他功能

3.1.1版本的功能2.1.1都能实现,参考3.1.1版本即可。

http://www.hrbkazy.com/news/23971.html

相关文章:

  • biz后缀域名的网站长沙网站推广智投未来
  • 电商网站构建预算方案国际新闻网站
  • wordpress实现tab网站建设优化
  • 乐清开发网站公司网站编辑怎么做
  • 如何做网站seo排名优化网络服务提供商
  • 猴哥影院在线电影观看贵阳网站优化公司
  • 做网站的生产方式产品品牌推广策划方案
  • 做电影网站有什么好处和坏处杭州旺道企业服务有限公司
  • 做系统网站百度知道合伙人
  • 用wordpress搭建知名网站自动推广引流app
  • 江苏企业网站建设公司网络推广排名定制
  • 手机h5网站模板市场营销专业就业方向
  • 泉州做网站需要多少钱电脑培训班速成班
  • python网站开发集成环境域名停靠
  • 专业的网站建设公网站的宣传与推广
  • 网站后台管理模板下载wap网站html5
  • 做平面有什么好的网站地推接单平台app排行榜
  • 网站后台登陆密码破解长沙百度推广运营公司
  • 网站推广方案书网站域名解析ip
  • 重庆网站制作服务百度网盘网页版官网
  • 哪个网站做漫画可以有钱推广平台 赚佣金
  • 建一个公司网站要多少钱新闻稿范文300字
  • 浙江住建局官方网站接广告推广的平台
  • 只做自己网站杭州网站优化公司
  • 各类东莞微信网站建设企业网站营销实现方式解读
  • 万润 企业网站建设网络营销
  • wordpress m编辑器seo外包推广
  • wordpress video插件搜索引擎优化方案
  • 专门做win7系统的网站电商营销推广有哪些?
  • 网站建设广州天河区品牌推广文案