Mini-Project: Command line speech synth tool for Windows
The story behind this mini-project is, a friend of mine mentioned how he would SSH into his Mac at home and use “say†to send a short message to his parents, just like in a past XKCD webcomic:
Mac users, lucky you. You get a Terminal utility called “say†that converts text to speech. Windows doesn’t come with this tool, so I thought, it couldn’t be that difficult to make my own command line speech synth tool for Windows.
After a bit of research, I found that it’s really quite easy to make thanks to the Speech libraries in the .NET framework. Yep – no more than 30 lines of spaced out C# code:
using System; using System.Speech.Synthesis; namespace speech { class say { static SpeechSynthesizer synth = new SpeechSynthesizer(); static void Main(string[] args) { if (args.Length == 0) { InteractiveMode(); return; } synth.Speak(string.Join(" ", args)); } static void InteractiveMode() { string line; while ((line = Console.ReadLine()) != null) { synth.Speak(line); } } } }
This application can either take its input as command line arguments, or from standard input if it is started without any arguments.
For example:
say.exe foo (computer says “fooâ€) say.exe foo bar (computer says “foo barâ€) say.exe “foo bar†(computer says “foo barâ€) say.exe (computer waits for further input) foo bar (computer says “foo bar†then waits for further input) CTRL+Z then ENTER exits the application
Source code: Speech Synthesiser VS10 Project (.zip, 38KB)
Binary file: say.exe (.exe, 7KB) requires .NET Client Profile 4.0
Enjoy!
