Fun with text-to-speech
more from apple
Apr 3, 07

Macs have great text-to-speech functionality, but I've only used it for fun. Specifically, if I want to "talk" to someone using my computer. As you might guess, this isn't too important but it sure can be fun.

The fastest way I know to make your Mac "talk" is to open a Terminal window and use the say command, like this:

% say blah blah blah

If you run that, you should hear a computer voice read everything after the word "say". If you don't have say available, maybe your path is screwed up. Mine's under /usr/bin:

% which say
/usr/bin/say

So that's part 1.

Part 2 is to make it easier to keep feeding speakable text.

To help, I wrote a small script that will wait for input (from you), send your input to say for speaking, then wait for another line of input. That way you can just keep typing text, hit return, rinse, repeat, and have some fun with friends, your cat, etc.

I made a file in my bin directory and named it "speak.command". (Anything that's a ".command" means you can double-click the filename in a Finder window and it will automatically launch a Terminal window using that script.)

% cat ~/bin/speak.command
#!/bin/tcsh
echo "start typing stuff to speak..."
while (1)
set input = $<:q
say "$input"
end

The full steps are thus....

  1. Create a file somewhere (probably ~/bin/) named "speak.command".
  2. Copy the contents of my script above, starting with #!/bin/tcsh
  3. Either double-click the file "speak.command" in a Finder window, or run it directly from Terminal like this: % ~/bin/speak.command
  4. Ctrl-d (or close window) when you're done