【问题标题】:Trying to work out how to improve Microsoft c# speech dictation recognition试图弄清楚如何改进 Microsoft c# 语音听写识别
【发布时间】:2014-05-20 12:13:52
【问题描述】:

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

目前与 Google 语音 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")

:-(

【问题讨论】:

  • 搜索“词典”。显示您的代码也会有所帮助。
  • 现在去看看词典,谢谢。
  • 此外,内置的识别引擎通过训练得到了很大的改进。如果您可以通过与波形文件来源相同的路径(相同的麦克风等)提供音频,那也会有很大帮助。
  • 我的词典一直很幸运,但是在尝试使用 en-GB 语言环境时遇到了问题,从我的猜测看来,音素不同,但我找不到任何东西确认这个或可能在 Microsoft 页面上的美国列表之外工作的音素列表,所以目前当我尝试使用这个 "lex.AddPronunciation("Katie", langid, SpeechPartOfSpeech.SPSNoun, "k ey t iy")" 除非我将 langid 设置为 en-US 而不是 en-GB?
  • 顺便说一句,您没有有指定发音;如果您不这样做,SR 引擎将使用默认规则。

标签: c# speech-to-text


【解决方案1】:

我希望你的问题是正确的。 这是我用的。 使用现有的东西并添加到它们。

    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

我认为您正在尝试丰富现有的语音识别器。如果不是,请澄清我的理解。 谢谢和干杯。

【讨论】:

  • 感谢显示了一些我没有注意到的有趣设置,但这是更多的命令和控制,而我在一般听写之后,对延迟响应表示歉意。
猜你喜欢
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-27
  • 2022-01-09
相关资源
最近更新 更多