我正在尝试为“语音转文字”创建一个控制台应用程序。 我编写了每次中断的示例代码。 在这里回答之前,我已经用Google搜索并竭尽全力。
`
using System;
using System.Windows;
using System.Data;
using System.IO;
using System.Net;
using System.Speech;
using System.Speech.Recognition;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Win32;
namespace Speech_recognition
{
class Program
{
static SpeechRecognitionEngine engine;
static void Main()
{
engine = new SpeechRecognitionEngine();
//engine.SetInputToDefaultAudioDevice();
Grammar g = new DictationGrammar();
engine.LoadGrammar(g);
//engine.LoadGrammar(new Grammar(DictationGrammar()));
engine.RecognizeAsync(RecognizeMode.Multiple);
engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);
Console.ReadLine();
}
static void engine_SpeechRecognized(object ob, SpeechRecognizedEventArgs e)
{
Console.WriteLine(e.Result.Text);
}
}
}
`
运行此程序时,我遇到以下错误:
Unhandled Exception: System.PlatformNotSupportedException: COM is not supported
at System.Speech.Internal.SapiInterop.SapiRecognizer..ctor(RecognizerType type)
at System.Speech.Recognition.SpeechRecognitionEngine.Initialize(RecognizerInfo recognizerInfo)
at Speech_recognition.Program.Main() in /Users/jayant/Desktop/NetC#Code/TextToSpeect/TextToSpeect/SpeechToText.cs:line 22
bash: line 1: 1858 Abort trap: 6 "/usr/local/share/dotnet/dotnet" "/Users/jayant/Desktop/NetC#Code/TextToSpeect/TextToSpeect/bin/Debug/netcoreapp2.1/SpeechToText.dll"
如果有人帮助我尝试理解该问题,那将是一个很大的帮助。谢谢