System.UnauthorizedAccessException的'发生在System.Speech.dll中

时间:2017-06-12 16:04:38

标签: c# speech-recognition

我发现了这个错误' System.UnauthorizedAccessException'发生在System.Speech.dll'是的我读了所有关于这个错误的问题,但任何可以解决我的错误,请帮助我,我有下一个代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Security.Permissions;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

    String speech;
    SpeechRecognitionEngine reconocedor = new SpeechRecognitionEngine();
    SpeechSynthesizer AVJarvis = new SpeechSynthesizer();

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        AVJarvis.Speak("Iniciando");
        AVJarvis.Speak("Buenos días Kevin");
        CargarGramatica();
    }

    void CargarGramatica()
    {
        reconocedor.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines("ComandosDefecto.txt"))))); //Cargo los comandos del .txt
        //reconocedor.LoadGrammarAsync(new DictationGrammar()); //Carga todas las gramaticas de mi sistema
        reconocedor.SpeechRecognized += reconocedor_SpeechRecognized;
        reconocedor.SetInputToDefaultAudioDevice();
        reconocedor.RecognizeAsync(RecognizeMode.Multiple);

    }

    void reconocedor_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        speech = e.Result.Text;

        switch (speech)
        {

            case "Buenos días Asistente":
                AVJarvis.Speak("Buenos días Kevin");
                break;

            default:
                break;

        }
    }
}

} Image

0 个答案:

没有答案