Skip to content

Instantly share code, notes, and snippets.

@spencerkittleson
Last active September 20, 2022 18:24
Show Gist options
  • Save spencerkittleson/4245a751c15faa32fa764982f542f886 to your computer and use it in GitHub Desktop.
Save spencerkittleson/4245a751c15faa32fa764982f542f886 to your computer and use it in GitHub Desktop.
AHK Text to Speech Everywhere!
// See https://aka.ms/new-console-template for more information
using SynthesizerAudio;
using System.Media;
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(10));
var text = string.Empty;
if (args.Length > 0 && File.Exists(args[0])) {
text = await File.ReadAllTextAsync(args[0], cts.Token) ?? string.Empty;
} else {
Environment.Exit(1);
}
var audioService = new SynthesizerWebAudioService();
var audio = await audioService.TextToSpeechAudioAsync(text, new TextToSpeechAudioOptions {
Format = SynthesizerAudio.SynthesizerWebAudioService.AUDIO_FORMAT.WAV,
VoiceName = "Zira",
});
using var player = new SoundPlayer { Stream = audio };
player.Load();
player.PlaySync();
Environment.Exit(0);
#c::
FileDelete,clip.txt
Process, Close, UserTriggerTextToSpeech.exe
Sendinput, ^{c} ; copy the selected text/item/whatever
Sleep 500
clipwait, 2,1
Current_Clipboard := Clipboard
FileAppend,%Current_Clipboard%,clip.txt
Run, UserTriggerTextToSpeech.exe clip.txt, , Hide
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment