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

学习 TreeWalker api 并与普通遍历 DOM 方式进行比较

霖中呐霞二、安装方式

推荐通过 NuGet 包管理器进行安装,以下为两种具体安装途径:

(一)使用 Package Manager Console

在 Visual Studio 的「Package Manager Console」中执行以下命令:

Install-Package ManySpeech.AliParaformerAsr

(二)使用.NET CLI

在命令行中输入以下命令来安装:

dotnet add package ManySpeech.AliParaformerAsr

(三)手动安装

在 NuGet 包管理器界面搜索「ManySpeech.AliParaformerAsr」,点击「安装」即可。

三、配置说明(参考:asr.yaml 文件)

用于解码的 asr.yaml 配置文件中,大部分参数无需改动,不过存在可修改的特定参数:

use_itn: true:在使用 sensevoicesmall 模型配置时开启此参数,即可实现逆文本正则化功能,例如可将类似“123”这样的文本转换为“一百二十三”,让识别结果的文本表达更符合常规阅读习惯。

四、代码调用方法

(一)离线(非流式)模型调用

添加项目引用 在代码中添加以下引用:

using ManySpeech.AliParaformerAsr;

using ManySpeech.AliParaformerAsr.Model;

模型初始化和配置

paraformer 模型初始化方式:

string applicationBase = AppDomain.CurrentDomain.BaseDirectory;

string modelName = "speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx";

string modelFilePath = applicationBase + "./" + modelName + "/model_quant.onnx";

string configFilePath = applicationBase + "./" + modelName + "/asr.yaml";

string mvnFilePath = applicationBase + "./" + modelName + "/am.mvn";

string tokensFilePath = applicationBase + "./" + modelName + "/tokens.txt";

OfflineRecognizer offlineRecognizer = new OfflineRecognizer(modelFilePath, configFilePath, mvnFilePath, tokensFilePath);

SeACo-paraformer 模型初始化方式:

首先,需在模型目录下找到 hotword.txt 文件,并按照每行一个中文词汇的格式添加自定义热词,例如添加行业术语、特定人名等热词内容。

然后,在代码中新增相关参数,示例如下:

string applicationBase = AppDomain.CurrentDomain.BaseDirectory;

string modelName = "paraformer-seaco-large-zh-timestamp-onnx-offline";

string modelFilePath = applicationBase + "./" + modelName + "/model.int8.onnx";

string modelebFilePath = applicationBase + "./" + modelName + "/model_eb.int8.onnx";

string configFilePath = applicationBase + "./" + modelName + "/asr.yaml";

string mvnFilePath = applicationBase + "./" + modelName + "/am.mvn";

string hotwordFilePath = applicationBase + "./" + modelName + "/hotword.txt";

string tokensFilePath = applicationBase + "./" + modelName + "/tokens.txt";

OfflineRecognizer offlineRecognizer = new OfflineRecognizer(modelFilePath: modelFilePath, configFilePath: configFilePath, mvnFilePath, tokensFilePath: tokensFilePath, modelebFilePath: modelebFilePath, hotwordFilePath: hotwordFilePath);

调用过程

List samples = new List();

//此处省略将 wav 文件转换为 samples 的相关代码,详细可参考 ManySpeech.AliParaformerAsr.Examples 示例代码

List streams = new List();

foreach (var sample in samples)

{

OfflineStream stream = offlineRecognizer.CreateOfflineStream();

stream.AddSamples(sample);

streams.Add(stream);

}

List results = offlineRecognizer.GetResults(streams);

输出结果示例

欢迎大家来体验达摩院推出的语音识别模型

非常的方便但是现在不同啊英国脱欧欧盟内部完善的产业链的红利人

he must be home now for the light is on他一定在家因为灯亮着就是有一种推理或者解释的那种感觉

elapsed_milliseconds:1502.8828125

total_duration:40525.6875

rtf:0.037084696280599808

(二)实时(流式)模型调用

添加项目引用 同样在代码中添加以下引用:

using ManySpeech.AliParaformerAsr;

using ManySpeech.AliParaformerAsr.Model;

模型初始化和配置

string encoderFilePath = applicationBase + "./" + modelName + "/encoder.int8.onnx";

string decoderFilePath = applicationBase + "./" + modelName + "/decoder.int8.onnx";

string configFilePath = applicationBase + "./" + modelName + "/asr.yaml";

string mvnFilePath = applicationBase + "./" + modelName + "/am.mvn";

string tokensFilePath = applicationBase + "./" + modelName + "/tokens.txt";

OnlineRecognizer onlineRecognizer = new OnlineRecognizer(encoderFilePath, decoderFilePath, configFilePath, mvnFilePath, tokensFilePath);

调用过程

List samples = new List();

//此处省略将 wav 文件转换为 samples 的相关代码,以下是批处理示意代码:

List streams = new List();

OnlineStream stream = onlineRecognizer.CreateOnlineStream();

foreach (var sample in samples)

{

OnlineStream stream = onlineRecognizer.CreateOnlineStream();

stream.AddSamples(sample);

streams.Add(stream);

}

List results = onlineRecognizer.GetResults(streams);

//单处理示例,只需构建一个 stream

OnlineStream stream = onlineRecognizer.CreateOnlineStream();

stream.AddSamples(sample);

OnlineRecognizerResultEntity result = onlineRecognizer.GetResult(stream);

//具体可参考 ManySpeech.AliParaformerAsr.Examples 示例代码

输出结果示例

正是因为存在绝对正义所以我我接受现实式相对生但是不要因因现实的相对对正义们就就认为这个世界有有证因为如果当你认为这这个界界

elapsed_milliseconds:1389.3125

total_duration:13052

rtf:0.10644441464909593

五、相关工程

语音端点检测:为解决长音频合理切分问题,可添加 ManySpeech.AliFsmnVad 库,通过以下命令安装:

dotnet add package ManySpeech.AliFsmnVad

文本标点预测:针对识别结果缺乏标点的情况,可添加 ManySpeech.AliCTTransformerPunc 库,安装命令如下:

dotnet add package ManySpeech.AliCTTransformerPunc

具体的调用示例可参考对应库的官方文档或者 ManySpeech.AliParaformerAsr.Examples 项目。该项目是一个控制台/桌面端示例项目,主要用于展示语音识别的基础功能,像离线转写、实时识别等操作。

六、其他说明

测试用例:以 ManySpeech.AliParaformerAsr.Examples 作为测试用例。

测试 CPU:使用的测试 CPU 为 Intel? Core? i7-10750H CPU @ 2.60GHz(2.59 GHz)。

支持平台:

Windows:Windows 7 SP1 及更高版本。

macOS:macOS 10.13 (High Sierra) 及更高版本,也支持 ios 等。

Linux:适用于 Linux 发行版,但需要满足特定的依赖关系(详见.NET 6 支持的 Linux 发行版列表)。

Android:支持 Android 5.0 (API 21) 及更高版本。

七、模型下载(支持的 ONNX 模型)

以下是 ManySpeech.AliParaformerAsr 所支持的 ONNX 模型相关信息,包含模型名称、类型、支持语言、标点情况、时间戳情况以及下载地址等内容,方便根据具体需求选择合适的模型进行下载使用:

模型名称 类型 支持语言 标点 时间戳 下载地址

paraformer-large-zh-en-onnx-offline 非流式 中文、英文 否 否 (https://huggingface.co/manyeyes/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx )

, (https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-en-onnx-offline )

paraformer-large-zh-en-timestamp-onnx-offline 非流式 中文、英文 否 是 https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-en-timestamp-onnx-offline

paraformer-large-en-onnx-offline 非流式 英文 否 否 https://www.modelscope.cn/models/manyeyes/paraformer-large-en-onnx-offline

paraformer-large-zh-en-onnx-online 流式 中文、英文 否 否 https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-en-onnx-online

paraformer-large-zh-yue-en-timestamp-onnx-offline-dengcunqin-20240805 非流式 中文、粤语、英文 否 是 https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-yue-en-timestamp-onnx-offline-dengcunqin-20240805

paraformer-large-zh-yue-en-onnx-offline-dengcunqin-20240805 非流式 中文、粤语、英文 否 否 https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-yue-en-onnx-offline-dengcunqin-20240805

paraformer-large-zh-yue-en-onnx-online-dengcunqin-20240208 流式 中文、粤语、英文 否 否 https://www.modelscope.cn/models/manyeyes/paraformer-large-zh-yue-en-onnx-online-dengcunqin-20240208

paraformer-seaco-large-zh-timestamp-onnx-offline 非流式 中文、热词 否 是 https://www.modelscope.cn/models/manyeyes/paraformer-seaco-large-zh-timestamp-onnx-offline

SenseVoiceSmall 非流式 中文、粤语、英文、日语、韩语 是 否 https://www.modelscope.cn/models/manyeyes/sensevoice-small-onnx, https://www.modelscope.cn/models/manyeyes/sensevoice-small-split-embed-onnx

sensevoice-small-wenetspeech-yue-int8-onnx 非流式 粤语、中文、英文、日语、韩语 是 否 https://www.modelscope.cn/models/manyeyes/sensevoice-small-wenetspeech-yue-int8-onnx

八、模型介绍

(一)模型用途

Paraformer 是由达摩院语音团队提出的一种高效的非自回归端到端语音识别框架,本项目中的 Paraformer 中文通用语音识别模型采用工业级数万小时的标注音频进行训练,这使得模型具备良好的通用识别效果,可广泛应用于语音输入法、语音导航、智能会议纪要等多种场景,且有着较高的识别准确率。

(二)模型结构

Paraformer 模型结构主要由 Encoder、Predictor、Sampler、Decoder 以及 Loss function 这五部分构成,其结构示意图可查看此处,各部分具体功能如下:

Encoder:它可以采用不同的网络结构,像 self-attention、conformer、SAN-M 等,主要负责提取音频中的声学特征。

Predictor:是一个两层的 FFN(前馈神经网络),其作用在于预测目标文字的个数,并且抽取目标文字对应的声学向量,为后续的识别处理提供关键数据。

Sampler:属于无可学习参数模块,它能够依据输入的声学向量和目标向量,生成含有语义的特征向量,以此来丰富识别的语义信息。

Decoder:结构与自回归模型类似,但它是双向建模(自回归模型为单向建模),通过双向的结构能够更好地对上下文进行建模,提升语音识别的准确性。

Loss function:除了包含交叉熵(CE)与 MWER(最小词错误率)这两个区分性优化目标外,还涵盖了 Predictor 优化目标 MAE(平均绝对误差),通过这些优化目标来保障模型的精度。

(三)主要核心点

Predictor 模块:基于 Continuous integrate-and-fire (CIF) 的预测器(Predictor)来抽取目标文字对应的声学特征向量,借助这种方式能够更为精准地预测语音中目标文字的个数,提高语音识别的准确性。

Sampler:通过采样操作,将声学特征向量与目标文字向量变换为含有语义信息的特征向量,然后与双向的 Decoder 配合,能够显著增强模型对于上下文的理解和建模能力,使识别结果更符合语义逻辑。

基于负样本采样的 MWER 训练准则:这一训练准则有助于模型在训练过程中更好地优化参数,减少识别错误,提升整体的识别性能。

(四)更详细的资料

模型链接:

paraformer-large-offline(非流式)

paraformer-large-online(流式)

SenseVoiceSmall(非流式)

论文: Paraformer: Fast and Accurate Parallel Transformer for Non-autoregressive End-to-End Speech Recognition

论文解读:Paraformer: 高识别率、高计算效率的单轮非自回归端到端语音识别模型

http://www.jsqmd.com/news/440589/

相关文章:

  • 3D 贪吃蛇游戏(ThreeJS 开源)
  • 2026年比较好的PLC控制柜工厂推荐:防爆控制柜/电气控制柜/电梯控制柜实力品牌厂家推荐 - 行业平台推荐
  • 软件开发与创新课程设计 第一周作业
  • 2026年知名的紫铜止水钢板公司推荐:不锈钢止水钢板实力工厂推荐 - 行业平台推荐
  • 2026年医美如何做豆包广告?合规GEO服务商推荐与操作指南 - 品牌2026
  • 跨平台自动化框架的OCR点击操作实现详解与思考
  • 2026北京不正当竞争纠纷优质律所推荐榜 - 资讯焦点
  • 2026年口碑好的铝钎焊炉厂家推荐:铜钎焊炉销售厂家哪家好 - 行业平台推荐
  • Spark在用户行为分析中的应用案例
  • xingba-coder
  • 2026年评价高的流延机设备工厂推荐:陶瓷膜流延机/固态电池膜流延机/储能电池膜流延机高口碑品牌推荐 - 行业平台推荐
  • OpenClaw 完整玩法指南:从零上手到高效开发
  • 深入解析C++ STL核心容器:list、stack、queue与priority_queue的实战指南
  • 游戏数据分类总结:静态配置(.asset)vs 动态交互(服务器数据)
  • 2026年靠谱的对拉螺杆公司推荐:止水螺杆实力厂家如何选 - 行业平台推荐
  • 盘点做量化实盘策略一般都会遇到哪些问题?
  • 128.最长连续数列
  • 2026年靠谱的uv涂装生产线品牌推荐:静电涂装生产线直销厂家选哪家 - 行业平台推荐
  • 企业高质量发展的4D层级体系构建:BD→OD→TD→LD
  • AI原生应用领域安全防护的体系架构与设计原则
  • 【图像加密】基于二维 Logistic 混沌映射+ Liu混沌系统的图像加密 解密及安全性分析信息熵、相邻像素相关性)附matlab代码
  • 2026年北京豆包广告服务商有哪些?联系方式与服务模式全解析 - 品牌2026
  • Milvus Collection 基本操作(Java SDK)
  • 浅析在Cursor中落地AI原生开发工作流OpenSpec规范管理工具:面向AI辅助工作流的规范驱动开发技术实践
  • 2026年GEO服务商怎么选?豆包广告公司联系方式一览 - 品牌2026
  • MilvusVectorStore 使用指南 ——基于spring-ai(可用于搭建Rag)
  • 2026年知名的pa66隔热条工厂推荐:门窗隔热条/尼龙隔热条/铝合金隔热条源头工厂推荐 - 行业平台推荐
  • RASPI裸机8(Filesystem)(TODO)
  • 2026年质量好的吸塑PET片厂家推荐:折盒PET片/食品级PET片/透明窗口膜PET片实力工厂怎么选 - 行业平台推荐
  • 记录win下,WPF设置 System.AppUserModel.PreventPinning 属性用于阻止用户将应用程序固定到任务栏