使用C#中的Dictionary與ConcurrentDictionary進行多線程操作 在C#中,Dictionary是一個常見的字典類型,但它不是線程安全的。為了在多線程環境中確保全全的操作,我們可以使用ConcurrentDictionary,這是一個專門設計用於多線程場景的線程安全字典。 1 ...
C#使用WhisperNet實現語音識別功能
1.寫在前面
最近想做一下本地音頻語音識別工具,在網上找了一些本地音頻語音識別方面的資料。
Whisper 是 OpenAI 的一種自動最先進的語音識別系統,它已經接受了 680000 小時從網路收集的多語言和多任務監督數據的訓練。這個龐大而多樣化的數據集提高了對口音、背景噪音和技術語言的魯棒性。此外,它還支持多種語言的轉錄,以及將這些語言翻譯成英語。與 DALLE-2 和 GPT-3 不同,Whisper 是一種免費的開源模型。 Whisper的優勢是開源免費、支持多語種(包括中文),根據不同的場景需求有不同模型可供選擇,最終的效果比市面上很多音頻轉文字的效果都要好。 Whisper提供了五種型號尺寸,其中四種為純英文版本,提供速度和準確性的權衡。以下是可用型號的名稱及其大致的記憶體要求和相對速度。![](https://pic1.zhimg.com/80/v2-347936bde5a06f2d5b7715de462f6997_720w.webp?source=2c26e567)
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
只有對寫程式充滿熱情,才能寫出好的程式!