Я не могу искать в Google, используя свой голос.По умолчанию я отключил поиск, и его можно включить только произнесением слова «поиск».Я разделил слова и фразы, которые нужно найти, в другой файл, чтобы он не смешивался с моим файлом распознавания и файлом ответов.Я поместил файл пути под оператором «поиска» if, чтобы к нему можно было получить доступ только тогда, когда я произнесу «поиск»
public partial class Form1 : Form
{
//user and jarvis texts
string[] grammarFile = (File.ReadAllLines(@"C:\Friday AI\user.txt.txt"));
string[] responseFile = (File.ReadAllLines(@"C:\Friday AI\jarvis.txt.txt"));
//speech synthesis
SpeechSynthesizer speechSynth = new SpeechSynthesizer();
//speech recognition
Choices grammarList = new Choices();
SpeechRecognitionEngine speechRecognition = new SpeechRecognitionEngine();
public Boolean search = false;
public Form1()
{
//initialize grammarfile
grammarList.Add(grammarFile);
Grammar grammar = new Grammar(new GrammarBuilder(grammarList));
try
{
speechRecognition.RequestRecognizerUpdate();
speechRecognition.LoadGrammar(grammar);
speechRecognition.SpeechRecognized += rec_SpeechRecognized;
speechRecognition.SetInputToDefaultAudioDevice();
speechRecognition.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return;
}
private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string result = e.Result.Text;
int resp = Array.IndexOf(grammarFile, result);
if (search)
{
Process.Start(@"chrome.exe", "--incognito https://www.google.com/search?q=" + result);
label5.Text = "Enabled";
}
if (wake == true)
{
if (result.Contains("search"))
{
search = true;
string[] globalsearch = (File.ReadAllLines(@"C:\Friday AI\global search words.txt"));
grammarList.Add(globalsearch);
label5.Text = "Enabled";
}