C#语音识别引擎识别出一切错误

时间:2015-02-26 11:45:31

标签: c# speech-recognition

我一直在尝试在空闲时间做个人助理,到目前为止我让他说话,但现在我想和他说话。然而,每当我这样做时,他都会大规模失败。当我说"你好,我的名字是亚历山大"他承认"在名称中是未解决的灌木"或其他不正确的东西。我做错了什么还是内置的C#识别引擎刚刚坏了?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TTS_Test
{
class Jarvis
{
    private static SpeechSynthesizer synthezier;
    private static String name;
    public Jarvis()
    {
        synthezier = new SpeechSynthesizer();
        synthezier.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Senior);
        synthezier.Volume = 100;
        synthezier.Rate = 0;
    }

    private bool isFirstTime() 
    {
        if (File.Exists("config"))
        {
            return false;
        }else{
            return true;
        }
    }

    private void firstTimeSetup()
    {
        say("Hello, My name is Jarvis. It seems that this is your first time here. Please take some time to configure the application.");
        Config config = new Config();
        config.ShowDialog();
        say("Thank you! I should be up and running now.");
    }

    public void initiate()
    {
        if (isFirstTime()) 
        {
            firstTimeSetup();
        }
        setupUserData();
        say("Hello " + name+". How may i help you today?");
        recognize();
    }

    public void setupUserData()
    {
        StreamReader reader = new StreamReader("config");
        name = reader.ReadLine();
        reader.Close();
    }

    public void say(string output)
    {
        synthezier.Speak(output);
    }

    public void recognize()
    {
        SpeechRecognitionEngine sr = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-GB"));
        sr.LoadGrammar(new DictationGrammar());
        sr.InitialSilenceTimeout = TimeSpan.FromSeconds(5);
        sr.SetInputToDefaultAudioDevice();
        RecognitionResult result = sr.Recognize();
        MessageBox.Show(result.Text);
    }
}
}

1 个答案:

答案 0 :(得分:1)

您应该通过转到控制面板\所有控制面板项目\语音识别来训练您的计算机以更好地了解您