Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.Speech.Synthesis;
  9.  
  10. namespace Jarvis_Pre_Build
  11. {
  12. class Program
  13. {
  14. private static SpeechSynthesizer synth = new SpeechSynthesizer();
  15.  
  16. #region Summary
  17. /// <summary>
  18. /// WHERE ALL THE MAGIC HAPPENS!
  19. /// </summary>
  20. /// <param name="args"></param>
  21. static void Main(string[] args)
  22. #endregion
  23. {
  24. #region Speech
  25. // This will greet the user in the default voice
  26. SpeechSynthesizer synth = new SpeechSynthesizer();
  27. synth.Speak("Welcome to Jarvis version point five three, Pre-Alpha Build");
  28. #endregion
  29.  
  30. #region My performance Counters
  31. // This will pull the current CPU load in percentage
  32. PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor time", "_Total");
  33.  
  34. // This will pull the current avaible memory in Megabytes
  35. PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
  36.  
  37. // This tells how long the system has been running. (in seconds)
  38. PerformanceCounter perfUpTimeCount = new PerformanceCounter("System", "System Up Time");
  39. perfUpTimeCount.NextValue();
  40. #endregion
  41.  
  42. #region Time Spans!
  43. TimeSpan uptimeSpan = TimeSpan.FromSeconds(perfUpTimeCount.NextValue());
  44. string systemUptimeMessage = string.Format("The current amount of time your system has been up is {0} hours, and {1} minutes",
  45. (int)uptimeSpan.Hours,
  46. (int)uptimeSpan.Minutes
  47. );
  48.  
  49. // Tells the user what the current system uptimes is!
  50. JerrySpeak(systemUptimeMessage, VoiceGender.Male, 2);
  51.  
  52. #endregion
  53.  
  54.  
  55. #region Infinite Loop
  56.  
  57. int speechSpeed = 1;
  58.  
  59. // Infinite While Loop
  60. while (true)
  61. {
  62. // Get the current performance current values.
  63. int currentCpuPercentage = (int)perfCpuCount.NextValue();
  64. int currentAvailableMemory = (int)perfMemCount.NextValue();
  65.  
  66. // Every 1 second print the CPU load in percentage to the screen
  67. Console.ForegroundColor = ConsoleColor.Green;
  68. Console.WriteLine("CPU Load: {0}%", currentCpuPercentage);
  69. Console.WriteLine("Available Memory: {0}MB", currentAvailableMemory);
  70.  
  71. // Only tell us when the CPU is above 80%
  72. if (currentCpuPercentage > 80)
  73. {
  74. if (currentCpuPercentage == 100)
  75. {
  76. if( speechSpeed <5 )
  77. {
  78. speechSpeed++;
  79. }
  80. string cpuLoadVocalMessage = String.Format("WARNING: Holy crap your CPU is about to catch fire!", currentCpuPercentage);
  81. JerrySpeak(cpuLoadVocalMessage, VoiceGender.Male, speechSpeed++);
  82.  
  83. }
  84. else
  85. {
  86. string cpuLoadVocalMessage = String.Format("The current CPU load is {0} percent", currentCpuPercentage);
  87. JerrySpeak(cpuLoadVocalMessage, VoiceGender.Female, 5);
  88.  
  89. Console.WriteLine("Please type something and press return");
  90. string userValue;
  91. userValue = Console.ReadLine();
  92. Console.WriteLine("You typed: " + userValue);
  93. Console.ReadLine();
  94.  
  95. }
  96.  
  97. }
  98.  
  99. // Only tell us when memory is below one gigabyte
  100. if (currentAvailableMemory < 1024)
  101. {
  102. string memAvailableVocalMessage = String.Format("You currently have {0} gigabytes of memory available", currentAvailableMemory / 1024);
  103. JerrySpeak(memAvailableVocalMessage, VoiceGender.Male, 10);
  104. }
  105.  
  106. Thread.Sleep(1000);
  107. }
  108.  
  109. }
  110. #endregion
  111. /// <summary>
  112. /// Speaks with a selected voice
  113. /// </summary>
  114. /// <param name="message"></param>
  115. /// <param name="voiceGender"></param"
  116. public static void JerrySpeak(string message, VoiceGender voiceGender)
  117. {
  118. synth.SelectVoiceByHints(VoiceGender.Male);
  119. synth.Speak(message);
  120. }
  121.  
  122. /// <summary>
  123. /// Speaks with a selected voice at a selected voice
  124. /// </summary>
  125. /// <param name="message"></param>
  126. /// <param name="voiceGender"></param"
  127. public static void JerrySpeak(string message, VoiceGender voiceGender, int rate)
  128. {
  129. synth.Rate = rate;
  130. JerrySpeak(message, voiceGender);
  131. }
  132.  
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement