Jarvis Google search API / image API

  • Thread starter Thread starter alffy
  • Start date Start date
A

alffy

Guest
Hi every one am building a speech recognitions like Jarvis in Iron man movies anyway i want if i ask some it will lookup in google or Bing and speak out to me as a result or display a image.

so far i didnt add any code for iam a little knowledge in C# please some out there help me....

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Xml;


namespace JARVIS
{
public partial class Form1 : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer JARVIS = new SpeechSynthesizer();
string QEvent;
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new DictationGrammar());
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Test\Documents\code\Jarvis\Commands.txt")))));
_recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
int ranNum = rnd.Next(1, 10);
string speech = e.Result.Text;
switch (speech)
{
//GREETINGS
case "*":
JARVIS.Speak("what sir?");
break;
case "hello":
case "hello jarvis":
if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
else if (ranNum > 5) { JARVIS.Speak("Hi"); }
break;
case "goodbye":
case "goodbye jarvis":
case "close":
case "close jarvis":
if (ranNum < 4){ JARVIS.Speak("Until next time"); }
else if (ranNum > 3) {JARVIS.Speak ("see you later");}
Close();
break;


case "jarvis":

if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); }
else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); }
break;

//SHELL COMMANDS
case "open itune":
case "jarvis can you open itune":
case "jarvis please open itune":
case "can you open itune":

System.Diagnostics.Process.Start(@"C:\Program Files\iTunes\itunes.exe");
if (ranNum < 6) { JARVIS.Speak("no problem, it shall be done"); }
else if (ranNum > 5) { JARVIS.Speak("there you go!"); }
break;

//CLOSE PROGRAMS
case "close itune":
ProcWindow = "itunes";

if (ranNum < 4) { JARVIS.Speak("ok i will look in to it. Closing i tune"); }
else if (ranNum > 3) { JARVIS.Speak("your request is in process sir");}
StopWindow();
if (ranNum < 6){JARVIS.Speak("i tune was close sir");}
else if (ranNum > 5) { JARVIS.Speak("sir? your request has been proccessed"); }
break;

case "close skype":
ProcWindow = "Skype";
if (ranNum < 4) { JARVIS.Speak("closing up skype"); }
else if (ranNum > 3) { JARVIS.Speak("proccessing to close your skype sir"); }
StopWindow();
if (ranNum < 4) { JARVIS.Speak("skype was closed"); }
else if (ranNum > 3) { JARVIS.Speak("Done as requested dir"); }
break;

//CONDITION OF DAY
case "what time is it":
case "what is the time":
DateTime now = DateTime.Now;
string time = now.GetDateTimeFormats(t)[0];
JARVIS.Speak(time);
break;
case "what day is it":
JARVIS.Speak(DateTime.Today.ToString("dddd"));
break;
case "whats the date":
case "whats todays date":
JARVIS.Speak(DateTime.Today.ToString("dd-MM-yyyy"));

break;

//OTHER COMMANDS
case "go full screen":
case "full screen":
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
TopMost = true;
if (ranNum < 4) { JARVIS.Speak("expanding"); }
else if (ranNum > 3) { JARVIS.Speak("going full screen"); }
break;
case "exit full screen":
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Normal;
TopMost = false;
JARVIS.Speak("ok!");
break;
case "switch window":
if (ranNum < 3){JARVIS.Speak("next window");}
else if (ranNum > 4) { JARVIS.Speak("switching to next application");}
SendKeys.Send("%{TAB " + count + "}");
count += 1;
break;
case "reset":
count = 1;
timer = 11;
lblTimer.Visible = false;
ShutdownTimer.Enabled = false;
lstCommands.Visible = false;
break;

//SHUTDOWN RESTART LOG OFF
case "shutdown":
if (ShutdownTimer.Enabled == false)
{
QEvent = "shutdown";
JARVIS.Speak("I will shutdown shortly");
lblTimer.Visible = true;
ShutdownTimer.Enabled = true;
}
break;
case "log off":
if (ShutdownTimer.Enabled == false)
{
QEvent = "logoff";
JARVIS.Speak("Logging off");
lblTimer.Visible = true;
ShutdownTimer.Enabled = true;
}
break;
case "restart":
if (ShutdownTimer.Enabled == false)
{
QEvent = "restart";
JARVIS.Speak("Ill be back shortly");
lblTimer.Visible = true;
ShutdownTimer.Enabled = true;
}
break;
case "abort":
if (ShutdownTimer.Enabled == true)
{
QEvent = "abort";
}
break;
case "speed up":
if (ShutdownTimer.Enabled == true)
{
ShutdownTimer.Interval = ShutdownTimer.Interval / 10;
}
break;
case "slow down":
if (ShutdownTimer.Enabled == true)
{
ShutdownTimer.Interval = ShutdownTimer.Interval * 10;
}
break;



}
}
private void ShutdownTimer_Tick(object sender, EventArgs e)
{
if (timer == 0)
{
lblTimer.Visible = false;
ComputerTermination();
ShutdownTimer.Enabled = false;
}
else if (QEvent == "abort")
{
timer = 10;
lblTimer.Visible = false;
ShutdownTimer.Enabled = false;
}
else
{
timer = timer - .01;
lblTimer.Text = timer.ToString();
}
}
private void ComputerTermination()
{
switch (QEvent)
{
case "shutdown":
System.Diagnostics.Process.Start("shutdown", "-s");
break;
case "logoff":
System.Diagnostics.Process.Start("shutdown", "-l");
break;
case "restart":
System.Diagnostics.Process.Start("shutdown", "-r");
break;
}
}
private void StopWindow()
{
System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName(ProcWindow);
foreach (System.Diagnostics.Process proc in procs)
{
proc.CloseMainWindow();
}
}


}


}

Continue reading...
 
Back
Top