C#使用whisper.net实现语音辨认(语音转文本)

打印 上一主题 下一主题

主题 997|帖子 997|积分 2991

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
目录
介绍
效果
输出信息 
项目
代码
下载 

介绍

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. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Whisper.net;
  12. using static System.Net.Mime.MediaTypeNames;
  13. namespace C_使用whisper.net实现语音转文本
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.         string fileFilter = "*.wav|*.wav";
  22.         string wavFileName = "";
  23.         WhisperFactory whisperFactory;
  24.         WhisperProcessor processor;
  25.         private async void button2_Click(object sender, EventArgs e)
  26.         {
  27.             if (wavFileName == "")
  28.             {
  29.                 return;
  30.             }
  31.             try
  32.             {
  33.                 button2.Enabled = false;
  34.                 using var fileStream = File.OpenRead(wavFileName);
  35.                 await foreach (var result in processor.ProcessAsync(fileStream))
  36.                 {
  37.                     Console.WriteLine($"{result.Start}->{result.End}: {result.Text}\r\n");
  38.                     txtResult.Text += $"{result.Start}->{result.End}: {result.Text}\r\n";
  39.                 }
  40.             }
  41.             catch (Exception ex)
  42.             {
  43.                 MessageBox.Show(ex.Message);
  44.             }
  45.             finally
  46.             {
  47.                 button2.Enabled = true;
  48.             }
  49.         }
  50.         private void Form1_Load(object sender, EventArgs e)
  51.         {
  52.             whisperFactory = WhisperFactory.FromPath("ggml-small.bin");
  53.             processor = whisperFactory.CreateBuilder()
  54.                .WithLanguage("zh")//.WithLanguage("auto")
  55.                .Build();
  56.             wavFileName = "085黄鹤楼.wav";
  57.             txtFileName.Text = wavFileName;
  58.         }
  59.         private void button1_Click(object sender, EventArgs e)
  60.         {
  61.             OpenFileDialog ofd = new OpenFileDialog();
  62.             ofd.Filter = fileFilter;
  63.             if (ofd.ShowDialog() != DialogResult.OK) return;
  64.             txtResult.Text = "";
  65.             wavFileName = ofd.FileName;
  66.             txtFileName.Text = wavFileName;
  67.         }
  68.     }
  69. }
复制代码
下载 

源码下载

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

美丽的神话

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表