gpt4 book ai didi

c# - PlatformNotSupportedException 使用 .NET 语音识别

转载 作者:行者123 更新时间:2023-11-30 17:13:25 27 4
gpt4 key购买 nike

所以我正在尝试 C# 的语音识别,我正在使用 System.Speech.Recognition,并且,我在互联网上四处搜索,尝试了一些代码来进行一些基本的语音识别,这是我能做到的最好的发现是这样的:

using System;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;

namespace SpeechRecognition
{
public partial class MainForm : Form
{

SpeechRecognitionEngine recognitionEngine;


public MainForm()
{
InitializeComponent();

Initialize();
}

private void Initialize()
{
recognitionEngine = new SpeechRecognitionEngine();
recognitionEngine.SetInputToDefaultAudioDevice();
recognitionEngine.SpeechRecognized += (s, args) =>
{
foreach (RecognizedWordUnit word in args.Result.Words)
{
// You can change the minimun confidence level here
if (word.Confidence > 0.8f)
freeTextBox.Text += word.Text + " ";
}
freeTextBox.Text += Environment.NewLine;
};
}

private void startButton_Click(object sender, EventArgs e)
{
try
{
recognitionEngine.UnloadAllGrammars();
recognitionEngine.LoadGrammar(new DictationGrammar());
RecognitionResult result = recognitionEngine.Recognize(new TimeSpan(0, 0, 20));

if (result != null)
{
foreach (RecognizedWordUnit word in result.Words)
{

freeTextBox.Text += word.Text + " ";
}
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void startAsyncButton_Click(object sender, EventArgs e)
{
recognitionEngine.UnloadAllGrammars();
recognitionEngine.LoadGrammar(new DictationGrammar());
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
}



private void stopButton_Click(object sender, EventArgs e)
{
recognitionEngine.RecognizeAsyncStop();
}


private void startAsyncGrammarButton_Click(object sender, EventArgs e)
{
try
{
recognitionEngine.UnloadAllGrammars();

Grammar cg = CreateSampleGrammar();
recognitionEngine.LoadGrammar(cg);
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}


private Grammar CreateSampleGrammar()
{
Choices commandChoices = new Choices("Calculator", "Notepad", "Internet Explorer", "Paint");
GrammarBuilder grammarBuilder = new GrammarBuilder("Start");
grammarBuilder.Append(commandChoices);
Grammar g = new Grammar(grammarBuilder);
g.Name = "Available programs";
return g;
}

}
}

现在,我尝试了这个和其他一些方法,它们都导致了相同的错误,一个 PlatformNotSupportedException,在错误中它说:“没有安装识别器”。

有什么办法解决这个问题吗?我正在运行 Windows 7 64 位。

最佳答案

The Speech Platform Runtime 11 and the Speech Platform SDK 11 do not include Runtime Languages for speech recognition or for speech synthesis (TTS or text-to-speech). You must install them separately. A Runtime Language includes the language model, acoustic model, and other data necessary to provision a speech engine to perform speech recognition or TTS in a particular language. There are separate Runtime Languages for speech recognition or speech synthesis. The version of Runtime Languages that you download (for example, version 11.0) must match the version of the Speech Platform Runtime that you have installed. You can download Runtime Languages using this link.

来自 http://msdn.microsoft.com/en-us/library/hh362873.aspx .

我认为您使用的是 .NET 附带的版本,但此后已经发布了多个修订版。 Microsoft Speech Services v11 是截至今天的最新版本。如果安装 SDK、添加引用并将命名空间更改为 Microsoft.Speech(而不是 System.Speech),则应该进行更新。

关于c# - PlatformNotSupportedException 使用 .NET 语音识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9741053/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com