Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. function Invoke-Sidious{
  2. Add-Type -TypeDefinition @'
  3. using System.Runtime.InteropServices;
  4.  
  5. [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  6. interface IAudioEndpointVolume {
  7. // f(), g(), ... are unused COM method slots. Define these if you care
  8. int f(); int g(); int h(); int i();
  9. int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext);
  10. int j();
  11. int GetMasterVolumeLevelScalar(out float pfLevel);
  12. int k(); int l(); int m(); int n();
  13. int SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, System.Guid pguidEventContext);
  14. int GetMute(out bool pbMute);
  15. }
  16. [Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  17. interface IMMDevice {
  18. int Activate(ref System.Guid id, int clsCtx, int activationParams, out IAudioEndpointVolume aev);
  19. }
  20. [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  21. interface IMMDeviceEnumerator {
  22. int f(); // Unused
  23. int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice endpoint);
  24. }
  25. [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] class MMDeviceEnumeratorComObject { }
  26.  
  27. public class Audio {
  28. static IAudioEndpointVolume Vol() {
  29. var enumerator = new MMDeviceEnumeratorComObject() as IMMDeviceEnumerator;
  30. IMMDevice dev = null;
  31. Marshal.ThrowExceptionForHR(enumerator.GetDefaultAudioEndpoint(/*eRender*/ 0, /*eMultimedia*/ 1, out dev));
  32. IAudioEndpointVolume epv = null;
  33. var epvid = typeof(IAudioEndpointVolume).GUID;
  34. Marshal.ThrowExceptionForHR(dev.Activate(ref epvid, /*CLSCTX_ALL*/ 23, 0, out epv));
  35. return epv;
  36. }
  37. public static float Volume {
  38. get {float v = -1; Marshal.ThrowExceptionForHR(Vol().GetMasterVolumeLevelScalar(out v)); return v;}
  39. set {Marshal.ThrowExceptionForHR(Vol().SetMasterVolumeLevelScalar(value, System.Guid.Empty));}
  40. }
  41. public static bool Mute {
  42. get { bool mute; Marshal.ThrowExceptionForHR(Vol().GetMute(out mute)); return mute; }
  43. set { Marshal.ThrowExceptionForHR(Vol().SetMute(value, System.Guid.Empty)); }
  44. }
  45. }
  46. '@
  47. Add-Type -AssemblyName System.Speech
  48.  
  49. # Identify current Mute status and Volume Level
  50. $CurrentMute = [Audio]::Mute
  51. $CurrentVol = [Audio]::Volume
  52.  
  53. # Un-mute if needed
  54. [Audio]::Mute = $False
  55. # If Volume is under 25%, change to 75%
  56. [Audio]::Volume = .25
  57.  
  58. # Intialize voice
  59. $Voice = New-Object System.Speech.Synthesis.SpeechSynthesizer
  60.  
  61. # Get current rate of speech. Probably set to 0(default)
  62. $CurrentRate = $Voice.Rate
  63.  
  64. # Change rate of speech
  65. $Voice.Rate = -2
  66. # Speak
  67.  
  68.  
  69.  
  70.  
  71. $Voice.Speak(
  72. "Did you ever hear the tragedy of Darth Plagueis The Wise?
  73. I thought not. Its not a story the Jedi would tell you.
  74. Its a Sith legend. Darth Plagueis was a Dark Lord of the Sith,
  75. so powerful and so wise he could use the Force to influence the midichlorians to create life…
  76. He had such a knowledge of the dark side that he could even keep the ones he cared about from dying.
  77. The dark side of the Force is a pathway to many abilities some consider to be unnatural.
  78. He became so powerful… the only thing he was afraid of was losing his power, which eventually, of course, he did.
  79. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep.
  80. Ironic. He could save others from death, but not himself."
  81. )
  82.  
  83. # Change Rate,Volume,Mute values back to what they were set to originally
  84. $Voice.Rate = $CurrentRate
  85. [Audio]::Volume = $CurrentVol
  86. [Audio]::Mute = $CurrentMute
  87.  
  88. # Dispose of voice
  89. $Voice.Dispose()
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement