简体   繁体   English

尝试找出如何改善Microsoft C#语音听写识别的方法

[英]Trying to work out how to improve Microsoft c# speech dictation recognition

Im trying to get the dictation recognition to be a bit more accurate. 我试图使听写识别更加准确。 I've loaded the dictation grammar and have been trying to read through all the documentation i can find online but can't seem to find a way to expand on the list of recognised words. 我已经加载了听写语法,并一直试图通读我在网上可以找到的所有文档,但似乎找不到找到可扩展的单词列表的方法。

Currently compared to the Google speech api the default recognition is atrocious so am looking at ways of improving on the default but am at a loss as where to start. 目前,与Google语音api相比,默认识别功能非常糟糕,因此我正在寻找改进默认设置的方法,但从何处着手。

This isn't about specific word recognition but more generic speech to text hence why I've not gone down the route of just building a custom word grammar. 这不是针对特定的单词识别,而是针对文本的更通用的语音表达,因此,为什么我没有遵循仅建立自定义单词语法的路线。

Thanks 谢谢

Si

Update: added basic code below which I took from an example I found: 更新:添加了下面的基本代码,下面是我从发现的示例中获取的代码:

    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();
    }

So the following works: 因此,以下工作:

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

but this doesn't: 但这不是:

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

:-( :-(

I hope i got your question right. 希望我能正确回答你的问题。 Here is what i used. 这是我用的。 Using existing things and adding to them. 使用现有事物并添加到它们中。

    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;
        }
    }       
}

You would also need to create a .txt file to load the grammar with the commands each in single line like below 您还需要创建一个.txt文件,以使用单行的命令加载语法,如下所示

Notepad
Close
Minimize
Maximize
Open
Hello

I presume you are trying to enrich the existing speech recognizer. 我想您正在尝试丰富现有的语音识别器。 If not, please clarify my understanding. 如果没有,请阐明我的理解。 Thanks and Cheers. 谢谢,干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM