我遵循了一个非常基本的教程(忘记了链接),这一切看起来都很简单,但我似乎没有得到我想要的输出。这是我的主要表单类:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
namespace OralNotes.Alpha
{
public partial class MainForm : Form
{
private SpeechRecognitionEngine recognitionEngine;
public MainForm()
{
InitializeComponent();
recognitionEngine = new SpeechRecognitionEngine();
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.SpeechRecognized += (s, args) =>
{
foreach (RecognizedWordUnit word in args.Result.Words)
{
if (word.Confidence > 0.8f)
txtNotes.Text += word.Text + " ";
}
txtNotes.Text += Environment.NewLine;
};
recognitionEngine.LoadGrammar(new DictationGrammar());
}
private void btnStart_Click(object sender, EventArgs e)
{
recognitionEngine.RecognizeAsync();
}
private void btnStop_Click(object sender, EventArgs e)
{
recognitionEngine.RecognizeAsyncStop();
}
}
}
你可能不需要这个,但无论如何它是这样的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace OralNotes.Alpha
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
我单击开始并交谈,但没有任何反应。
更新*
好的,如果我调整这条线,这是可行的
if (word.Confidence > 0.8f)
到一个较低的数字,我得到一两个词。不转录句子或任何东西,有没有办法让它有更好的识别?