Advertisement
Guest User

Untitled

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