当前位置: 首页 > news >正文

广州网站建设排名百度网盘网址是多少

广州网站建设排名,百度网盘网址是多少,营销型网站如何制作,嘉定企业网站建设要在.NET Framework 4.8中使用C#实现离线实时语音识别,可以使用开源库Vosk(支持离线ASR)配合音频处理库NAudio。 步骤 1:安装依赖库 1.1. 安装NuGet包: - Install-Package NAudio(处理音频输入&#xff09…

要在.NET Framework 4.8中使用C#实现离线实时语音识别,可以使用开源库Vosk(支持离线ASR)配合音频处理库NAudio。

步骤 1:安装依赖库
1.1.
安装NuGet包:
- Install-Package NAudio(处理音频输入)
- Install-Package Vosk(离线语音识别引擎)
2.2.
下载语音模型:
- 前往 Vosk Models 下载适合的模型(如小型英文模型 vosk-model-small-en-us-0.15)。
- 解压模型到项目目录(如 Models/vosk-model-small-en-us-0.15)。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NAudio.Wave;
using Vosk;
using System.Windows.Forms;
namespace 语音识别
{
public class RealTimeSpeechRecognizer
{private readonly VoskRecognizer _recognizer;private readonly WaveInEvent _waveIn;private readonly RichTextBox _rtb;public RealTimeSpeechRecognizer(string modelPath, RichTextBox rtb){_rtb = rtb;// 初始化VoskModel model = new Model(modelPath);_recognizer = new VoskRecognizer(model, 16000.0f);_recognizer.SetWords(true);// 初始化音频输入_waveIn = new WaveInEvent{WaveFormat = new WaveFormat(16000, 16, 1),DeviceNumber = 0};_waveIn.DataAvailable += OnAudioDataAvailable;}public void StartListening() => _waveIn.StartRecording();public void StopListening() => _waveIn.StopRecording();// 解析JSON结果(兼容部分结果)private string ParseJsonResult(string json, bool isPartial = false){dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);return isPartial ? obj.partial : obj.text;}// 线程安全更新RichTextBoxprivate void ShowText(string text){if (_rtb.InvokeRequired){_rtb.BeginInvoke(new Action<string>(ShowText), text);}else{_rtb.AppendText(text);_rtb.ScrollToCaret();}}// 其他字段和构造函数保持不变...private string _lastPartialText = string.Empty;private void OnAudioDataAvailable(object sender, WaveInEventArgs e){if (_recognizer.AcceptWaveform(e.Buffer, e.BytesRecorded)){string result = ParseJsonResult(_recognizer.Result());ClearLastPartial(); // 清理临时部分AppendFinalText(result);}else{string partial = ParseJsonResult(_recognizer.PartialResult(), isPartial: true);UpdatePartialText(partial);}}private void UpdatePartialText(string newPartial){if (newPartial == _lastPartialText) return;// 在主线程更新UI_rtb.BeginInvoke(new Action(() =>{int selectionStart = _rtb.TextLength - _lastPartialText.Length;// 删除旧临时内容if (selectionStart >= 0 && _lastPartialText.Length > 0){_rtb.Select(selectionStart, _lastPartialText.Length);_rtb.SelectedText = "";}// 追加新内容_rtb.AppendText(newPartial);_rtb.ScrollToCaret();// 更新临时记录_lastPartialText = newPartial;}));}private void AppendFinalText(string text){_rtb.BeginInvoke(new Action(() =>{_rtb.AppendText(text + "\n");_lastPartialText = string.Empty; // 重置临时部分}));}private void ClearLastPartial(){if (string.IsNullOrEmpty(_lastPartialText)) return;_rtb.BeginInvoke(new Action(() =>{int start = _rtb.TextLength - _lastPartialText.Length;if (start >= 0){_rtb.Select(start, _lastPartialText.Length);_rtb.SelectedText = "";}}));}
}}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 语音识别
{
public partial class Form1 : Form
{
private RealTimeSpeechRecognizer _recognizer;
public Form1()
{
InitializeComponent();
btnStop.Enabled = false;
}private void button1_Click(object sender, EventArgs e){_recognizer.StopListening();btnStart.Enabled = true;btnStop.Enabled = false;}private void btnStart_Click(object sender, EventArgs e){string modelPath = @"E:\Models\vosk-model-small-cn-0.22"; // 中文模型路径_recognizer = new RealTimeSpeechRecognizer(modelPath, richTextBox1);btnStart.Enabled = false;btnStop.Enabled = true;_recognizer.StartListening();}
}}

http://www.yayakq.cn/news/871539/

相关文章:

  • 做网站和做网页一样吗wordpress英文版主题
  • 佛山微网站价格建站推广文案
  • 茶艺馆网站最新网游排行榜2024
  • 企业网站icp备案下载的asp网站怎么打开
  • 论坛网站推广方案黄页88网企业名录搜索软件
  • 二级域名 电子商务网站推广方案甘肃兰州地震最新消息
  • 定制型网站建设服务器青海省建筑信息平台
  • 商务网站创建流程是什么网页设计师联盟网站怎么
  • 长春做网站好的公司网页美工工资水平
  • 网站建设升级天津品牌网站建设是什么
  • 免费手机网站空间游戏编辑器
  • 网址域名ip查询子域名解析沈阳网站seo外包
  • 岗顶网站建设阿里免费版企业邮箱
  • 杭州网站建设seo做我的世界缩略图的网站
  • 21天网站建设实录pdf深圳企业网站建设推广外包服务商
  • 架设一个网站python基础教程电子版书籍
  • 多国语言网站手机版wordpress
  • 曲靖网站建设公司微商城下载
  • 网站代做多少钱上海注册设计公司网站
  • 福州网站建设公司中小企业wordpress 如何调用函数
  • 唐山网站制作价格上海手机网站制作公司
  • 永顺网站建设网站建设全流程 知乎
  • 成品ppt的网站免费直播有哪些手机怎么制作视频短片
  • 做网站链接容易吗织梦网站打开速度慢
  • 站长工具天美传媒免费网络推广
  • 青岛小型网站建设编程网站scratch在线使用
  • wordpress 单点登录网站搜索引擎优化的方法
  • 建设网站需要下载神呢软件吗做得比较好的公司网站
  • 网站开发软件开发如何看网站的浏览量
  • 网站开发的开发意义53建筑人才网