如何使用语音命令openfiledialog

时间:2017-09-27 16:35:39

标签: c# forms

我想使用语音命令打开OpenFileDialog我有一个例外我无法查看文件对话框我使用表单应用程序,这是我的代码:

        private void StartVoiceCommand(object sender, SpeechRecognizedEventArgs e)
    {
       else if(e.Result.Text == "media")
        {
            SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Teen);
            speechSynthesizer.Speak("Choose media files");
            speechSynthesizer.Dispose();
            openFilesToolStripMenuItem.PerformClick();
        }
    }

并且openfiletoolstripmenuitem代码为:

[STAThread]
private void openFilesToolStripMenuItem_Click(object sender, EventArgs e)
{

OpenFileDialog open = new OpenFileDialog();
    open.Filter = "Media Files|*.mp3;*.mp4";
    open.Multiselect = true;
    if(DialogResult.OK == open.ShowDialog())
    {
        files = open.SafeFileNames;
        path = open.FileNames;
        for(int i =0;i<files.Length;i++)
        {
            listBox1.Items.Add(files[i]);
        }
    }
}

这是我的Program.cs代码

    static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

这是一张异常图片 enter image description here

0 个答案:

没有答案