java code to make jarvis


SUBMITTED BY: vishaldagar

DATE: July 21, 2017, 3:07 p.m.

FORMAT: Text only

SIZE: 3.7 kB

HITS: 3188

  1. //////////////here voice search ////////////////////////////
  2. SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
  3. Grammar dictationGrammar = new DictationGrammar();
  4. recognizer.LoadGrammar(dictationGrammar);
  5. try
  6. {
  7. recognizer.SetInputToDefaultAudioDevice();
  8. RecognitionResult result = recognizer.Recognize();
  9. try
  10. {
  11. input.Text = result.Text;
  12. input.Update();
  13. }
  14. catch (Exception)
  15. {
  16. computer.Speak("Could not recognize input from default aduio device. Is a microphone or sound card available");
  17. }
  18. finally
  19. {
  20. recognizer.UnloadAllGrammars();
  21. }
  22. }
  23. //////////Search Button code ///////////////////
  24. string urlAddress = input.Text;
  25. webBrowser.Navigate("https://www.bing.com/search?q=/" + urlAddress);
  26. /////////end here ///////////////////////////
  27. thats it you done ...
  28. ///////////////////////Open file from base directory //////////////////////////////////////////////////////
  29. String Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
  30. Process process = new Process();
  31. process.StartInfo = new ProcessStartInfo()
  32. {
  33. FileName = Path + "\\Documents\\somePDFfile.pdf"
  34. };
  35. process.Start();
  36. //////////////////For Shutdown Restart Log Off Commands ////////////////////////
  37. First, add this using namespace statements:
  38. using System.Diagnostics;
  39. using System.Runtime.InteropServices;
  40. To shut down your computer, use this code:
  41. Process.Start("shutdown","/s /t 0");
  42. To restart your computer, use this code:
  43. Process.Start("shutdown","/r /t 0"); // the argument /r is to restart the computer
  44. To add this extern method to your class for (Log off)
  45. [DllImport("user32")]
  46. public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
  47. Then, to log off, invoke the method:
  48. ExitWindowsEx(0,0);
  49. To lock your computer, add this extern method to your class:
  50. [DllImport("user32")]
  51. public static extern void LockWorkStation();
  52. Then, to lock, invoke the method:
  53. LockWorkStation();
  54. To put your computer in Hibernate or Sleep, you need the same DllImport statement for them.
  55. [DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  56. public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
  57. To bring your computer into Hibernate:
  58. SetSuspendState(true, true, true);
  59. And to bring it into sleep:
  60. SetSuspendState(false, true, true);
  61. ///////////////////////////How to write text in notepad using textbox ////////////////////////////////////////////
  62. using System;
  63. using System.Collections.Generic;
  64. using System.ComponentModel;
  65. using System.Data;
  66. using System.Diagnostics;
  67. using System.Drawing;
  68. using System.Linq;
  69. using System.Runtime.InteropServices;
  70. using System.Text;
  71. using System.Threading.Tasks;
  72. using System.Windows.Forms;
  73. namespace MyForm
  74. {
  75. public partial class Form1 : Form
  76. {
  77. [DllImport("user32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  78. [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
  79. public Form1()
  80. {
  81. InitializeComponent();
  82. }
  83. private void Form1_Load(object sender, EventArgs e)
  84. {
  85. System.Diagnostics.Process.Start("notepad.exe");
  86. }
  87. private void button1_Click(object sender, EventArgs e)
  88. {
  89. Process[] notepads = Process.GetProcessesByName("notepad"); if (notepads.Length == 0) return; if (notepads[0] != null)
  90. {
  91. IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
  92. SendMessage(child, 0x000C, 0, textBox1.Text);
  93. }
  94. }
  95. }
  96. }

comments powered by Disqus