Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Use new say command for easy Terminal speech UNIX
In Panther, there is now a say command line tool. Type say "hello" and it will be said. In Jaguar, you could do this with osascript and the AppleScript "say" command, but this is a little simpler and cleaner.

This can also be used to read a file with the -f parameter, and to write to an AIFF sound file (-o option, useful for, say creating a spoken version of a file to go to your iPod). You can also choose the voice (-v parameter); see the man say page for more details.

[robg adds: This is a nice new feature, especially the ability to speak directly to an AIFF file!]

    •    
  • Currently 2.83 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[74,505 views]  

10.3: Use new say command for easy Terminal speech | 29 comments | Create New Account
Click here to return to the '10.3: Use new say command for easy Terminal speech' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Use new say command for easy Terminal speech
Authored by: pwharff on Nov 20, '03 11:54:38AM

What would be really funny, SSH to your Mac, use osascript to turn the volume all the way up on your Mac (set volume 6) and then "say" something to someone at home, like your wife or kids!!! Like I might say: "Hello? This is the crazy and possesed Mac speaking to you. Do what I say or I will start saying knock knock jokes."

I'm not sure if this would work through SSH, but I guess it would. BTW, whats the highest interger for setting the volume all the way up?



[ Reply to This | # ]
works via SSH
Authored by: matx666 on Nov 20, '03 12:13:47PM

as long as you have an account with shell acess (remote login turned on too) then you can do this. It worked with the osascript tip and now with say. Very useful. Remind those students they should not be eating in the lab, or something.



[ Reply to This | # ]
works via SSH
Authored by: ulrich on Nov 20, '03 01:19:53PM

LOL



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: spacebrother on Nov 20, '03 02:37:54PM

I've been trying to build a little app based on say, but I'm just a web guy:

http://www.robotradio.net/



[ Reply to This | # ]
Re: Practical joke
Authored by: bmerlin on Dec 03, '03 04:14:24PM

Yeah, I've done this to people. Yes, it's hilarious.

Kinda reminds me of a Classic extension called Radiation. Allowed you to create standard dialog boxes on any computer on the network. The default was great: "The radiation shield on your Macintosh has failed. Please step back 5 feet."



[ Reply to This | # ]
Re: Practical joke
Authored by: NeutronMonk on Mar 02, '04 08:29:53AM
I've had fun with this I've hacked this to replace the picture of Triumph the Insult Comic Dog with my own ( far scarier/funnier, depending on your point of view :) ) and my own innane audio. Read the "review" here

[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: tomsinclair on Nov 20, '03 11:54:57AM

Very cool! I also like the fact that they put in a man page for it so we didn't have to fumble around for usage hints.

On a side note, I really appreciate all of the Panther 'hidden gems' that I find here.



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: ChiperSoft on Nov 20, '03 12:40:19PM
If you have PHP enabled on your copy of panther, you can use the following php file to have a little fun:

<html><body>
<form method="post">
	Say: <input type="text" name="text" size="40">
	<input type="submit">
</form>
</body></html>

<?php
if (isset($_POST['text'])) {
	exec('say "'.$_POST['text'].'"');
}
?>


[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: Anonymous on Nov 20, '03 03:06:52PM

This sounds like an exceptionally bad idea to me. A malicious user could just type in a quote, followed by &&, followed by any malicious command, and then another quote to match the one at the end. You REALLY don't want to give arbitrary users permission to execute shell commands on your system.



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: rbest on Nov 20, '03 07:28:47PM

Since what ever the user types is in quotes, what could the user type that would do anything other than speak the text.
Example: I tried to enter: hello " && open /Applications/Calculator.app
and nothing happened. Please, if I'm wrong and someone CAN do something malicious, please correct me.



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: ua on Nov 20, '03 09:54:00PM
Looks like:
"; rm -rf /
would be pretty bad.

[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: aranor on Nov 20, '03 10:34:14PM
put escapeshellarg() around the $_POST['text']

[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: drakedave on Nov 21, '03 03:06:10AM

A bit funnier...
<code>
<?
$selected="";
switch($_POST['QUI']){
case 'Agnes' : $selected[1] ="SELECTED";break;
case 'Albert' : $selected[2] ="SELECTED";break;
case 'Bad News' : $selected[3] ="SELECTED";break;
case 'Bahh' : $selected[4] ="SELECTED";break;
case 'Bells' : $selected[5] ="SELECTED";break;
case 'Boing' : $selected[6] ="SELECTED";break;
case 'Bruce' : $selected[7] ="SELECTED";break;
case 'Bubbles' : $selected[8] ="SELECTED";break;
case 'Cellos' : $selected[9] ="SELECTED";break;
case 'Deranged' : $selected[10] ="SELECTED";break;
case 'Fred' : $selected[11] ="SELECTED";break;
case 'Hysterical' : $selected[12] ="SELECTED";break;
case 'Junior' : $selected[13] ="SELECTED";break;
case 'Kathy' : $selected[14] ="SELECTED";break;
case 'Pipe Organ' : $selected[15] ="SELECTED";break;
case 'Princess' : $selected[16] ="SELECTED";break;
case 'Ralph' : $selected[17] ="SELECTED";break;
case 'Trinoids' : $selected[18] ="SELECTED";break;
case 'Vicky' : $selected[19] ="SELECTED";break;
case 'Victoria' : $selected[20] ="SELECTED";break;
case 'Whisper' : $selected[21] ="SELECTED";break;
case 'Zarvox' : $selected[22] ="SELECTED";break;
}
?>

<html><body>
<form method="post">
<select name="QUI">
<option <? echo $selected[1]?>>Agnes</option>
<option <? echo $selected[2]?>>Albert</option>
<option <? echo $selected[3]?>>Bad News</option>
<option <? echo $selected[4]?>>Bahh</option>
<option <? echo $selected[5]?>>Bells</option>
<option <? echo $selected[6]?>>Boing</option>
<option <? echo $selected[7]?>>Bruce</option>
<option <? echo $selected[8]?>>Bubbles</option>
<option <? echo $selected[9]?>>Cellos</option>
<option <? echo $selected[10]?>>Deranged</option>
<option <? echo $selected[11]?>>Fred</option>
<option <? echo $selected[12]?>>Hysterical</option>
<option <? echo $selected[13]?>>Junior</option>
<option <? echo $selected[14]?>>Kathy</option>
<option <? echo $selected[15]?>>Pipe Organ</option>
<option <? echo $selected[16]?>>Princess</option>
<option <? echo $selected[17]?>>Ralph</option>
<option <? echo $selected[18]?>>Trinoids</option>
<option <? echo $selected[19]?>>Vicki</option>
<option <? echo $selected[20]?>>Victoria</option>
<option <? echo $selected[21]?>>Whisper</option>
<option <? echo $selected[22]?>>Zarvox</option>
</select>
Say: <textarea name="text"><? echo $_POST['text']?></textarea>
<input type="submit">
</form>
</body>

</html>

<?php
if (isset($_POST['text'])) {
exec('say -v "'.$_POST['QUI'].'" "'.$_POST['text'].'"');
}
?>
</code>

---
Take care,
Drake



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: Lectrick on Nov 21, '03 04:31:29AM
I added some security, and timestamped logging, in case you miss the performance. (Make sure the Unix permissions on the log directory are appropriate!) I am a php newbie ;) Now time for bed!
----------------------

<html><body>
<form method="post">
        Make my Mac say: <input type="text" name="text" size="40">
        <input type="submit">
</form>
</body></html>

<?php
if (isset($_POST['text'])) {
		$s = escapeshellcmd($_POST['text']);
		system("say \"$s\"");
		$fp = fopen("/Path/to/log/file.txt","a");
		fwrite($fp,date("d M Y h:i:s A")."\t".$s."\n");
		fclose($fp);
}
?>

---
In /dev/null, no one can hear you scream

[ Reply to This | # ]

10.3: Use new say command for easy Terminal speech
Authored by: thecolor on Mar 05, '06 06:21:07PM

Can you think of why I am only able to hear speech through my cmd line and Salling Clicker but not when I use your script via php?

I am positive my php5 setup is running and working as I utilize if wit my server mail script on my site.

Thanks,
~thecolor



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: thecolor on Mar 23, '06 07:32:46AM

it seems to be working now. Unsure why as I've not changed any of my settings. :)

Thanks



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: cstuder on Nov 20, '03 01:50:22PM
More fun:

say 94870342956230954792347592037452345

Gives you new insights what to do once you've made your first million dollars. :-)

Bye,
christian

[ Reply to This | # ]

Update - use commas
Authored by: zacht on Apr 30, '08 09:19:19AM
At least in Leopard, use commas:

say 94,870,342,956,230,954,792,347,592,037,452,345

[ Reply to This | # ]

Jaguar Too!
Authored by: thinkyhead on Nov 20, '03 05:25:16PM

This command lives in Jaguar also. I've been using this command to freak out people on the Macs I can ssh into for over a year now.

---
|
| slur was here
|



[ Reply to This | # ]
Jaguar Too!
Authored by: mcclint on Nov 21, '03 12:05:09PM

Where is it in Jaguar? I've searched my whole system and can't find it anywhere. Yes I do have the BSD subsystem installed and I'm running 10.2.6.



[ Reply to This | # ]
Jaguar Too!
Authored by: robg on Nov 21, '03 03:39:10PM

I only know of it existing in Jaguar with the "osascript" command -- which executes AppleScript's 'say,' not the shell's say (try saying that five times quickly!)

-rob.



[ Reply to This | # ]
Oh yeah....
Authored by: thinkyhead on Nov 21, '03 06:18:43PM

Nevermind, I forgot I had made my own "say" command using osascript.

---
|
| slur was here
|



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: Isamu Dyson on Nov 21, '03 03:12:48AM

anyone notice that if you do the command: say "x", or say "mac x" or say "this is an example of saying x" that the voice will pronounce x as ecks, but if you type: say "mac os x" or "os x" then it will pronounce x as "ten"? I know, this is how its supposed to be said, I was just tickled by this detail.



[ Reply to This | # ]
Can't get -o or -f options to work
Authored by: dtrevas on Nov 21, '03 12:10:07PM

If you look at "man say", you'll see the -o option to send spoken data to an aiff file and a -f option to read the contents of a text file.

In the directory /Users/myusername/Documents, I created a plan-text file called myfile.txt. Here's what happened:

say "Hello" SUCCESS
say -v Vicki "Hello" SUCCESS

but ALL of these failed with a return code of -1:

say -v Vicki -o mysound.aiff -f myfile.txt
say -f myfile.txt
say -v Vicki -f myfile.txt
say -v Vicki -o "mysound.aiff" -f "myfile.txt"

Does anyone see what I've done wrong or has anyone succeeded with the -o or -f options and what did it take to get there?

Any help will be appreciated.



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: oink on Nov 21, '03 12:24:51PM

Sounds play but I also get this error:

## Component Manager: attempting to find symbols in a component alias of type (regR/carP/x!bt)

Any clue of what it is?



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: kholburn on Nov 21, '03 10:13:15PM
## Component Manager: attempting to find symbols in a component alias of type (regR/carP/x!bt)

Any clue of what it is?

Yes, it's Toast. Just do a search on this site for : regR/carP


[ Reply to This | # ]
My own version (secure, valid and nice).
Authored by: androse on Nov 21, '03 07:49:38PM
Okay, this is my version. I saved it as
/Library/WebServer/Documents/index.php
and removed the default apache stuff. Now my co-workers can heckle me via RendezVous :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>Heckle me !</title>
	<style type="text/css">
	
		body {
			padding: 100px 0 0 40px;
			background: #f2f2f2;
			font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif;
			font-size: 16px;
			color: #ccc;
		}
		p.output span.green {
			color: #0c0;
		}	
	</style>
</head>
<body>
	<?php
		$voices = array('Agnes', 'Albert', 'Bad News', 'Bahh', 'Bells', 'Boing', 'Bruce', 'Bubbles', 'Cellos', 'Deranged', 'Fred', 'Hysterical', 'Junior', 'Kathy', 'Pipe Organ', 'Princess', 'Ralph', 'Trinoids', 'Vicki', 'Victoria', 'Whisper', 'Zarvox');
		if(strlen($_REQUEST['heckle'])) {
			if(strlen($_REQUEST['voice']) && in_array($_REQUEST['voice'], $voices)) {
				$voice = '-v '.$_REQUEST['voice'].' ';
			} else {
				$voice = '';
			}
			$heckle = escapeshellcmd(stripslashes($_REQUEST['heckle']));
			system('say '.$voice.$heckle.' &');
		
		
			echo '<p class="output">you said :<br />« <span class="green">';
			echo htmlentities($_REQUEST['heckle']);
			echo '</span> »</p>';
		} else {
			echo '<p>Heckle Ned!</p>';
		}
	?>
	
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		<p><select name="voice" id="voice">
<?php
			foreach($voices as $vox) {
				if($vox == $_REQUEST['voice']) {
					echo "\t\t\t<option selected=\"selected\">$vox</option>\n";
				} else {
					echo "\t\t\t<option>$vox</option>\n";
				}
			}
?>
			</select>
			<input type="text" maxlength="60" name="heckle" id="heckle" />
			<input type="submit" value="HECKLE NED" />
		</p>
	</form>

</body>
</html>


[ Reply to This | # ]
My own version (secure, valid and nice).
Authored by: thecolor on Mar 23, '06 07:30:37AM

I'm curious if anyone is familure with a way to pipe this command through to the visiting clients speakers or preferably the beep speaker. Obviously the voice does not need a serious subwoofer... and the beep speaker is always active.

It works great on my end... but I'd like to pass 'say' sounds to users visiting as well. I've not located any such question on the forum yet (and a difficult one to tailor in Google. ;)

Thanks



[ Reply to This | # ]
10.3: Use new say command for easy Terminal speech
Authored by: thecolor on Mar 23, '06 08:28:40AM

Here's a fun one. :)

say Super cala fraj ee listick ex pee al a doashus



[ Reply to This | # ]