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