C#使用whisper.net实现语音识别功能
脚本之家 / 编程助手:解决程序员“几乎”所有问题!
脚本之家官方知识库 → 点击立即使用
介绍
github地址:https://github.com/sandrohanea/whisper.net
Whisper.net. Speech to text made simple using Whisper Models
模型下载地址:https://huggingface.co/sandrohanea/whisper.net/tree/main/classic
效果
输出信息
whisper_init_from_file_no_state: loading model from 'ggml-small.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab = 51865
whisper_model_load: n_audio_ctx = 1500
whisper_model_load: n_audio_state = 768
whisper_model_load: n_audio_head = 12
whisper_model_load: n_audio_layer = 12
whisper_model_load: n_text_ctx = 448
whisper_model_load: n_text_state = 768
whisper_model_load: n_text_head = 12
whisper_model_load: n_text_layer = 12
whisper_model_load: n_mels = 80
whisper_model_load: ftype = 1
whisper_model_load: qntvr = 0
whisper_model_load: type = 3
whisper_model_load: mem required = 743.00 MB (+ 16.00 MB per decoder)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx = 464.68 MB
whisper_model_load: model size = 464.44 MB
whisper_init_state: kv self size = 15.75 MB
whisper_init_state: kv cross size = 52.73 MB
00:00:00->00:00:20: 皇鶴楼,崔昊,西人已成皇鶴去,此地空于皇鶴楼,皇鶴一去不复返,白云千载空悠悠。
00:00:20->00:00:39: 青川莉莉汉阳树,方草七七英五周,日暮相关何处事,燕泊江上世人愁。
项目
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Whisper.net; using static System.Net.Mime.MediaTypeNames; namespace C_使用whisper.net实现语音转文本 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string fileFilter = "*.wav|*.wav" ; string wavFileName = "" ; WhisperFactory whisperFactory; WhisperProcessor processor; private async void button2_Click( object sender, EventArgs e) { if (wavFileName == "" ) { return ; } try { button2.Enabled = false ; using var fileStream = File.OpenRead(wavFileName); await foreach (var result in processor.ProcessAsync(fileStream)) { Console.WriteLine($ "{result.Start}->{result.End}: {result.Text}\r\n" ); txtResult.Text += $ "{result.Start}->{result.End}: {result.Text}\r\n" ; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { button2.Enabled = true ; } } private void Form1_Load( object sender, EventArgs e) { whisperFactory = WhisperFactory.FromPath( "ggml-small.bin" ); processor = whisperFactory.CreateBuilder() .WithLanguage( "zh" ) //.WithLanguage("auto") .Build(); wavFileName = "085黄鹤楼.wav" ; txtFileName.Text = wavFileName; } private void button1_Click( object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = fileFilter; if (ofd.ShowDialog() != DialogResult.OK) return ; txtResult.Text = "" ; wavFileName = ofd.FileName; txtFileName.Text = wavFileName; } } } |
到此这篇关于C#使用whisper.net实现语音识别功能的文章就介绍到这了,更多相关C#语音识别内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
微信公众号搜索 “ 脚本之家 ” ,选择关注
程序猿的那些事、送书等活动等着你
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 reterry123@163.com 进行投诉反馈,一经查实,立即处理!
相关文章
详解ObjectARX开发环境的创建与开发实例Hello World(VS2005+AutoCad2008+Object
这篇文章主要介绍了ObjectARX开发环境的创建与开发实例Hello World(VS2005+AutoCad2008+ObjectArx2008),本文通过图文实例相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-04-04jQuery uploadify在谷歌和火狐浏览器上传失败的解决方案
jquery.uploadify插件是一个基于jquery来实现上传的,这个插件很好用,每一次向后台发送数据流请求时,ie会自动把本地cookie存储捆绑在一起发送给服务器。但firefox、chrome不会这样做,他们会认为这样不安全,下面介绍下jQuery uploadify上传失败的解决方案2015-08-08
最新评论