Created
February 11, 2016 21:05
-
-
Save margusmartsepp/755e1f5322d0343d438f to your computer and use it in GitHub Desktop.
SpeechSynthesizer with global hookups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Speech.Synthesis; | |
using System.Windows.Forms; | |
using Gma.System.MouseKeyHook; | |
namespace SoundSynthesize | |
{ | |
internal class Program | |
{ | |
public static SpeechSynthesizer Talk; | |
// Install-Package MouseKeyHook | |
[STAThread] | |
public static void Main() | |
{ | |
using (var hook = Hook.GlobalEvents()) | |
using (Talk = new SpeechSynthesizer()) | |
{ | |
hook.MouseDownExt += MouseEvent; | |
Talk.Rate = 5; | |
while (!Console.KeyAvailable) | |
Application.DoEvents(); | |
} | |
} | |
private static void MouseEvent(object sender, MouseEventExtArgs e) | |
{ | |
if (e.Button == MouseButtons.XButton2) | |
{ | |
SendKeys.SendWait("^{c}"); | |
var text = Clipboard.GetText(TextDataFormat.Text); | |
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] Play: \n{text}"); | |
Talk.SpeakAsync(text); | |
} | |
if (e.Button == MouseButtons.XButton1) | |
{ | |
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] Stop"); | |
Talk.SpeakAsyncCancelAll(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment