这适用于 windows 桌面,而不是 web ......在 C# 中使用 Visual Studio 2013。在 windows 7 中。
您好,我正在从头开始重新创建一个“Windows 语音识别器”... si 工作得非常好...我需要做什么 si 来检查打开了哪些 Windows 进程(即记事本、Firefox 等),然后是 IF 记事本是打开的,做某事......而不必自己调用那个动作......就像自动......打开记事本......警报说“你好记事本”......我关闭记事本”一个动作说“关闭记事本”。 ..我尝试了 12948305380453 不同的东西,但我唯一完成的是它写了一个数字......当我关闭并重新打开记事本时......这个数字不同......我需要进程名称......就像“ Windows 任务管理器中的 notepad.exe" "firefox.exe"...
抱歉,我没有要发布的代码,因为我实际上没有这部分的代码...谢谢...
该程序(记事本)将手动打开,因此代码需要不断跟踪任务管理器进程。并在代码中的一个变量中给我结果(例如,字符串“PNAME”,所以我可以在我的其余代码中使用该变量。
我只需要它告诉我 Notepad.exe 是否打开(即 True 或 False)即可使用
如果 notepad.exe 已打开,请执行此操作 如果 notepad.exe 已关闭,则不执行任何操作
好的......代码相当大......所以我会尝试发布最相关的......
我正在使用的“usign”是......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Text;
using System.Windows.Forms;
using System.Threading;
我已经初始化了一个不使用 Windows UI 或其命令的语音识别引擎(即,如果我说打开 Firefox”它什么也不做,因为它不在他的语法中)
然后我加载了我自己的语法
private Grammar CreateCustomGrammar()
{
GrammarBuilder GeneralCommands = new GrammarBuilder();
GeneralCommands.Append(new Choices("cut", "copy", "paste", "Read Clipboard", "help", "Close Recognition", "Turn Dictation On", "Read That"));
return new Grammar(GeneralCommands);
recognizer.LoadGrammar(GeneralCommands);
}
并为语法中的每个单词添加了一个开关,以便它知道该怎么做
private void SpeechToAction(string text)
{
DetermineText(text);
switch (text)
{
case "cut":
//cut();
speed();
break;
case "copy":
copy();
break;
case "paste":
paste();
break;
case "Read Clipboard":
readClipboard();
break;
case "Read That":
readThat();
break;
case "Turn Dictation Off":
TurnDictationOff();
break;
case "help":
help();
break;
case "Close Recognition":
Exit();
break;
}
}
如果我想使用另一个应用程序“即记事本”,所有这些都在后台工作
但是如果有一些命令我想在“记事本”是前台应用程序时激活......我就卡在那里了
我知道理论...
它会是这样的
(在我添加的所有代码之前)
//here is the tricky part
IF //notepad is the foreground and var notepadOK == 1
{
private Grammar NEWNAME()
{
GrammarBuilder NEWNAME = new GrammarBuilder();
GeneralCommands.Append(new Choices("Hole notepad", "save"));
return new Grammar(NEWNAME);
var notepadOK = 0
}
}
IF //notepad is NOT in the foreground and notepadOK == 0
{
// unload Notepad Grammar (i remember how to do this part, just cant find //it in the code
}