Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using System.Threading;
- using System.Speech.Synthesis;
- namespace Jarvis_Pre_Build
- {
- class Program
- {
- private static SpeechSynthesizer synth = new SpeechSynthesizer();
- #region Summary
- /// <summary>
- /// WHERE ALL THE MAGIC HAPPENS!
- /// </summary>
- /// <param name="args"></param>
- static void Main(string[] args)
- #endregion
- {
- #region Speech
- // This will greet the user in the default voice
- SpeechSynthesizer synth = new SpeechSynthesizer();
- synth.Speak("Welcome to Jarvis version point five three, Pre-Alpha Build");
- #endregion
- #region My performance Counters
- // This will pull the current CPU load in percentage
- PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor time", "_Total");
- // This will pull the current avaible memory in Megabytes
- PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes");
- // This tells how long the system has been running. (in seconds)
- PerformanceCounter perfUpTimeCount = new PerformanceCounter("System", "System Up Time");
- perfUpTimeCount.NextValue();
- #endregion
- #region Time Spans!
- TimeSpan uptimeSpan = TimeSpan.FromSeconds(perfUpTimeCount.NextValue());
- string systemUptimeMessage = string.Format("The current amount of time your system has been up is {0} hours, and {1} minutes",
- (int)uptimeSpan.Hours,
- (int)uptimeSpan.Minutes
- );
- // Tells the user what the current system uptimes is!
- JerrySpeak(systemUptimeMessage, VoiceGender.Male, 2);
- #endregion
- #region Infinite Loop
- int speechSpeed = 1;
- // Infinite While Loop
- while (true)
- {
- // Get the current performance current values.
- int currentCpuPercentage = (int)perfCpuCount.NextValue();
- int currentAvailableMemory = (int)perfMemCount.NextValue();
- // Every 1 second print the CPU load in percentage to the screen
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("CPU Load: {0}%", currentCpuPercentage);
- Console.WriteLine("Available Memory: {0}MB", currentAvailableMemory);
- // Only tell us when the CPU is above 80%
- if (currentCpuPercentage > 80)
- {
- if (currentCpuPercentage == 100)
- {
- if( speechSpeed <5 )
- {
- speechSpeed++;
- }
- string cpuLoadVocalMessage = String.Format("WARNING: Holy crap your CPU is about to catch fire!", currentCpuPercentage);
- JerrySpeak(cpuLoadVocalMessage, VoiceGender.Male, speechSpeed++);
- }
- else
- {
- string cpuLoadVocalMessage = String.Format("The current CPU load is {0} percent", currentCpuPercentage);
- JerrySpeak(cpuLoadVocalMessage, VoiceGender.Female, 5);
- Console.WriteLine("Please type something and press return");
- string userValue;
- userValue = Console.ReadLine();
- Console.WriteLine("You typed: " + userValue);
- Console.ReadLine();
- }
- }
- // Only tell us when memory is below one gigabyte
- if (currentAvailableMemory < 1024)
- {
- string memAvailableVocalMessage = String.Format("You currently have {0} gigabytes of memory available", currentAvailableMemory / 1024);
- JerrySpeak(memAvailableVocalMessage, VoiceGender.Male, 10);
- }
- Thread.Sleep(1000);
- }
- }
- #endregion
- /// <summary>
- /// Speaks with a selected voice
- /// </summary>
- /// <param name="message"></param>
- /// <param name="voiceGender"></param"
- public static void JerrySpeak(string message, VoiceGender voiceGender)
- {
- synth.SelectVoiceByHints(VoiceGender.Male);
- synth.Speak(message);
- }
- /// <summary>
- /// Speaks with a selected voice at a selected voice
- /// </summary>
- /// <param name="message"></param>
- /// <param name="voiceGender"></param"
- public static void JerrySpeak(string message, VoiceGender voiceGender, int rate)
- {
- synth.Rate = rate;
- JerrySpeak(message, voiceGender);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement