C#使用WhisperNet实现语音识别功能
1.写在前面
最近想做一下本地音频语音识别工具,在网上找了一些本地音频语音识别方面的资料。
Whisper 的性能因语言而异。下图显示了使用该模型的 Fleurs 数据集按语言的 WER(单词错误率)细分large-v2(数字越小,性能越好)。中文为14.7%
2.下载地址
源码下载地址:https://github.com/Const-me/Whisper
模型下载地址:https://huggingface.co/sandrohanea/whisper.net/tree/main/classic
3.程序实现
下面将贴出实现该程序的关键代码。
private async void buttonAsr_Click(object sender, EventArgs e) { string[] list = Library.listGraphicAdapters(); CommandLineArgs cla = new CommandLineArgs(); cla.language = eLanguage.Chinese; cla.gpu = textGpu.Text; cla.model = textModel.Text; cla.fileName = textFile.Text; cla.prompt = "这是一段播客的内容。"; cla.output_srt = true; using iModel model = await Library.loadModelAsync(cla.model, new CancellationToken(), eGpuModelFlags.Cloneable, cla.gpu); int[]? prompt = null; if (!string.IsNullOrEmpty(cla.prompt)) prompt = model.tokenize(cla.prompt); //using Context context = model.createContext(); context = model.createContext(); cla.apply(ref context.parameters); context.parameters.setFlag(eFullParamsFlags.NoContext, true); using iMediaFoundation mf = Library.initMediaFoundation(); Transcribe transcribe = new Transcribe(cla); using iAudioReader reader = mf.openAudioFile(cla.fileName, cla.diarize); await context.runFullAsync(reader, transcribe, UpdateProgress, prompt); }
4.程序界面
5.功能
本地音频语音识别。
程序中包含WhisperDesktop.exe
下载地址:https://pan.baidu.com/s/1c8r7HO2XvGocEuVIwdddpQ?pwd=6666 提取码:6666