试图找出如何改进微软c#语音听写识别

本文关键字:语音 识别 微软 何改进 | 更新日期: 2023-09-27 18:04:08

我试着让听写识别更准确一点。我已经加载了听写语法,并一直试图阅读我能在网上找到的所有文档,但似乎找不到一种方法来扩展可识别的单词列表。

目前,与谷歌语音api相比,默认识别非常糟糕,所以我正在寻找改进默认识别的方法,但我不知道从哪里开始。

这不是关于特定的单词识别,而是关于文本的更一般的语音,因此为什么我没有沿着构建自定义单词语法的路线走下去。

感谢

如果

更新:添加了下面的基本代码,我从一个例子中找到:

    static void Main(string[] args)
    {
        SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-GB"));
        Grammar gr = new DictationGrammar();
        sre.LoadGrammar(gr);
        sre.SetInputToWaveFile("C:''AudioStuff''file.wav");
        sre.BabbleTimeout = new TimeSpan(Int32.MaxValue);
        sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue);
        sre.EndSilenceTimeout = new TimeSpan(100000000);
        sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000);
        StringBuilder sb = new StringBuilder();
        while (true)
        {
            try
            {
                var recText = sre.Recognize();
                if (recText == null)
                {
                    break;
                }
                sb.Append(recText.Text);
            }
            catch (Exception ex)
            {
                //handle exception      
                //...
                break;
            }
        }
        Console.WriteLine(sb.ToString());
        Console.WriteLine();
        Console.WriteLine("Hit any key to exit");
        Console.ReadLine();
    }

所以下面的工作:

SpLexicon lex = new SpLexicon();
int langid = new System.Globalization.CultureInfo("en-US").LCID;
lex.AddPronunciation("Katie", langid, SpeechPartOfSpeech.SPSNoun, "k ey t iy")

但这不是:

SpLexicon lex = new SpLexicon();
int langid = new System.Globalization.CultureInfo("en-GB").LCID;
lex.AddPronunciation("Katie", langid, SpeechPartOfSpeech.SPSNoun, "k ey t iy")

: -

试图找出如何改进微软c#语音听写识别

我希望我答对了你的问题。这是我用的。使用已有的东西并对其进行添加。

    public partial class MainWindow : Window
    {
        SpeechRecognitionEngine _recognizer;
        SpeechSynthesizer sre = new SpeechSynthesizer();
        int count = 1;
        public MainWindow()
    {
        InitializeComponent();
        Initialize();
    }
    private void Initialize()
    {
        try
        {
            var culture = new CultureInfo("en-US");
            _recognizer = new SpeechRecognitionEngine(culture);
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammar(GetGrammer());
            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);
            sre.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Child);
            sre.Rate = -2;
        }
        catch (Exception ex)
        {
            System.Windows.MessageBox.Show(ex.InnerException.Message);
        }
    }
    private static Grammar GetGrammer()
    {
        var choices = new Choices();
        //add custom commands
        choices.Add(File.ReadAllLines(@"Commands.txt"));
        //to add the letters to the dictionary
        choices.Add(Enum.GetNames(typeof(Keys)).ToArray());
        var grammer = new Grammar(new GrammarBuilder(choices));
        return grammer;
    }
    void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        string speech = e.Result.Text; 
    //to type letters in open application like notepad
   if (Enum.GetNames(typeof(Keys)).Contains(speech))
    {
        try
        {   //send the string to the application
            SendKeys.SendWait("{" + speech + "}");
        }
        catch (ArgumentException)
        {
        }            
    }  
    //handle custom commands
        switch (speech)
        {
            case "Hello":
                sre.Speak("Goodmorning ");
                break;
            case "Notepad":
                System.Diagnostics.Process.Start("Notepad");
                break;
            case "Maximize":
                this.WindowState = System.Windows.WindowState.Maximized;
                break;
            case "Minimize":
                this.WindowState = System.Windows.WindowState.Minimized;
                break;
            case "Restore":
                this.WindowState = System.Windows.WindowState.Normal;
                break;
            case "Close":
                Close();
                break;
        }
    }       
}

您还需要创建一个.txt文件来加载语法,其中每个命令在单行中,如下所示

Notepad
Close
Minimize
Maximize
Open
Hello

我猜你是在尝试丰富现有的语音识别器。如果不是,请澄清我的理解。谢谢大家,干杯。