Guest User

Code

a guest
Jun 12th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.net.URL;
  4.  
  5.  
  6. import edu.cmu.sphinx.frontend.util.Microphone;
  7. import edu.cmu.sphinx.recognizer.Recognizer;
  8. import edu.cmu.sphinx.result.Result;
  9. import edu.cmu.sphinx.util.props.ConfigurationManager;
  10. import edu.cmu.sphinx.util.props.PropertyException;
  11.  
  12.  
  13. public class HelloWorld {
  14.  
  15. /**
  16. * Main method for running the HelloWorld demo.
  17. */
  18. static int i=1;
  19. static String resultText;
  20. public static void main(String[] args) {
  21. try {
  22. URL url;
  23. if (args.length > 0) {
  24. url = new File(args[0]).toURI().toURL();
  25. } else {
  26. url = HelloWorld.class.getResource("helloworld.config.xml");
  27. }
  28.  
  29. System.out.println("Loading...");
  30.  
  31. ConfigurationManager cm = new ConfigurationManager(url);
  32.  
  33. Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
  34. Microphone microphone = (Microphone) cm.lookup("microphone");
  35.  
  36.  
  37. /* allocate the resource necessary for the recognizer */
  38. recognizer.allocate();
  39.  
  40. /* the microphone will keep recording until the program exits */
  41.  
  42. if (microphone.startRecording())
  43. {
  44. System.out.println("Say: (Command | Program| Browser | Bluetooth | Device Manager |Power Options |Cal | Control | Player |task manager | Windows Security Center)");
  45. System.out.println("Say: ( open word | open phot oshop|open Access|start Excel|start nero |start fire wall| open Pad |open Paint)");
  46. while (true)
  47. {
  48.  
  49.  
  50. System.out.println("Start speaking. Press Ctrl-C to quit.\n");
  51.  
  52. /*
  53. * This method will return when the end of speech
  54. * is reached. Note that the endpointer will determine
  55. * the end of speech.
  56. */
  57.  
  58.  
  59. Result result = recognizer.recognize();
  60. if (result != null)
  61. {
  62.  
  63. System.out.println("Enter your choise"+ "\n");
  64. resultText = result.getBestFinalResultNoFiller();
  65. System.out.println("You said: " + resultText + "\n");
  66.  
  67. if(resultText.equalsIgnoreCase("command"))
  68. {
  69. try{
  70. Process p;
  71. //resultText="";
  72. p = Runtime.getRuntime().exec("cmd /c start");
  73. //System.out.println("You said");
  74.  
  75. //resultText = result.getBestFinalResultNoFiller();
  76. //System.out.println("You said: " + resultText + "\n");
  77.  
  78. }catch(Exception e){}
  79. }
  80. if (resultText.equalsIgnoreCase("Power Options"))
  81. {
  82. try{
  83. Process p;
  84. p = Runtime.getRuntime().exec("cmd /c powercfg.cpl");
  85.  
  86. }catch(Exception ae){}
  87. }
  88. if (resultText.equalsIgnoreCase("Blue"))
  89. {
  90. try{
  91. Process p;
  92. p = Runtime.getRuntime().exec("cmd /c fsquirt");
  93.  
  94. }catch(Exception ae){}
  95. }
  96. if (resultText.equalsIgnoreCase("start photo shop"))
  97. {
  98. try{
  99. Process p;
  100. p = Runtime.getRuntime().exec("start photoshop");
  101.  
  102. }catch(Exception ae){}
  103. }
  104. if (resultText.equalsIgnoreCase("CAL"))
  105. {
  106. try{
  107. Process p;
  108. p = Runtime.getRuntime().exec("cmd /c calc");
  109.  
  110. }catch(Exception ae){}
  111. }
  112. if (resultText.equalsIgnoreCase("Windows Security Center"))
  113. {
  114. try{
  115. Process p;
  116. p = Runtime.getRuntime().exec("cmd /c wscui.cpl");
  117.  
  118. }catch(Exception ae){}
  119. }
  120. else if (resultText.equalsIgnoreCase("Player"))
  121. {
  122. try{
  123. Process p;
  124. p = Runtime.getRuntime().exec("cmd /c start wmplayer");
  125. }catch(Exception ae){}
  126. }
  127. else if (resultText.equalsIgnoreCase("Programs"))
  128. {
  129. try{
  130. Process p;
  131. p = Runtime.getRuntime().exec("cmd /c start appwiz.cpl");
  132. }catch(Exception ae){}
  133. }
  134. else if (resultText.equalsIgnoreCase("Control"))
  135. {
  136. try{
  137. Process p;
  138. p = Runtime.getRuntime().exec("cmd /c control");
  139. }catch(Exception ae){}
  140. }
  141. else if(resultText.equalsIgnoreCase("open paint"))
  142. { try{
  143. Process p;
  144. p = Runtime.getRuntime().exec("cmd /c start mspaint");
  145. }catch(Exception ae){}
  146. }
  147. else if (resultText.equalsIgnoreCase("Browser"))
  148. {
  149. try{
  150. Process p;
  151. p = Runtime.getRuntime().exec("cmd /c iexplore");
  152. }catch(Exception ae){}
  153. }
  154. else if(resultText.equalsIgnoreCase("task manager"))
  155. { try{
  156. Process p;
  157. p = Runtime.getRuntime().exec("cmd /c start taskmgr.exe");
  158. }catch(Exception ae){}
  159. }
  160. else if (resultText.equalsIgnoreCase("open pad"))
  161. {
  162. try{
  163. Process p;
  164. p = Runtime.getRuntime().exec("cmd /c start notepad");
  165. }catch(Exception ae){}
  166. }
  167. else if (resultText.equalsIgnoreCase("open word"))
  168. {
  169. try{
  170. Process p;
  171. p = Runtime.getRuntime().exec("cmd /c start winword");
  172. }catch(Exception ae){}
  173. }
  174.  
  175. else if (resultText.equalsIgnoreCase("start Excel"))
  176. {
  177. try{
  178. Process p;
  179. p = Runtime.getRuntime().exec("cmd /c start excel");
  180. }catch(Exception ae){}
  181. }
  182. else if (resultText.equalsIgnoreCase("start firewall"))
  183. {
  184. try{
  185. Process p;
  186. p = Runtime.getRuntime().exec("cmd /c start firewall.cpl");
  187. }catch(Exception ae){}
  188. }
  189. else if (resultText.equalsIgnoreCase("open Access"))
  190. {
  191. try{
  192. Process p;
  193. p = Runtime.getRuntime().exec("cmd /c start msaccess");
  194. }catch(Exception ae){}
  195. }
  196. else if (resultText.equalsIgnoreCase("Device Manager"))
  197. {
  198. try{
  199. Process p;
  200. p = Runtime.getRuntime().exec("cmd /c start devmgmt.msc");
  201. }catch(Exception ae){}
  202. }
  203.  
  204. }
  205.  
  206. else
  207. {
  208. System.out.println("I can't hear what you said.\n");
  209. }
  210. }
  211. }
  212. else
  213. {
  214. System.out.println("Cannot start microphone.");
  215. recognizer.deallocate();
  216. System.exit(1);
  217. }
  218.  
  219. } catch (IOException e) {
  220. System.err.println("Problem when loading HelloWorld: " + e);
  221. e.printStackTrace();
  222. } catch (PropertyException e) {
  223. System.err.println("Problem configuring HelloWorld: " + e);
  224. e.printStackTrace();
  225. }
  226.  
  227. }
  228. }
Advertisement
Add Comment
Please, Sign In to add comment