LoudHush Icon

LoudHush
Overview

info@loudhush.ro



© Modulo Consulting 2005-2010



Playing with Apple's Text-To-Speech, LoudHush and Jack OS X



"I sure like being inside this fancy computer" says Bruce, one of the voices built in every Mac OS copy out there.

Well, I wouldn't know about that, but you can have your fancy Apple computer call your cell phone and read your email for you. While a better, more reliable and faster mail reader can be built using Asterisk and the Festival TTS, this article tries to show you how you can do the same thing using AppleScript.

What makes it happen is Jack OS X, which is a "connection kit implementation". In plain English, that means Jack allows you to use sound produced by one application (Apple's text to speech system in our case) as input for another application (an IAX client in our case). This is possible using a Jack OS X component that acts as a sound driver.

Requirements

An fancy Apple computer and some software. My test session was carried out on a Powerbook 17'' with Tiger 10.4.3. Software you will need:

Step by step procedure

1. Start iTunes and play a playlist. Any playlist, just make sure the iTunes outputs sound, otherwise Jack will not display the iTunes ports.

2. Start JackPilot

3. Start Jack (click on the Start button in the Jack Router window)

4. Bring up the connections panel (click on Routing in JackPanel)

Click iTunes in the "Send Ports" table view of the Connection Manager window
Double click LoudHush in the "Receive Ports" table view of the Connections Manager window. LoudHush should turn red.

Bring up LoudHush preferences
Choose JackRouter as sound input device.
Bring up System prefereces
Choose JackRouter as system default output device.

The next step is writing an applescript to glue it all together.
I came up with the one below (download here):

tell application "LoudHush"
	
	
	placecall to "NNNNNNNNNN" 
	-- cell phone number to dial 
	-- wait for an answer, hopefully we'll \\
		get one in 20 seconds (outside PSTN line)
	-- if you call an internal extension, you \\
		should have a 2 or 3 seconds delay
	delay 20
	
	tell application "iTunes"
		set wasplaying to 0
		if player state is playing then
			set wasplaying to 1
			pause
		end if
	end tell
	
	tell application "Mail"
		set everyAccount to every account
		repeat with eachAccount in everyAccount
			
			set myMailbox to mailbox "Inbox" \\
				of eachAccount
			set messageObject to first message \\
				of myMailbox
						
			set messageContent to content \\
				of messageObject
			set speakableContent to text 1 \\
				thru 150 of messageContent
			
			try
			with timeout of 10 seconds
				tell application "iTunes" \\
					to say "Welcome to \\
					LoudHush [[emph +]] mail reader \\
					[[slnc 500; pmod +1; pbas +1]]" \\
					& speakableContent
			end timeout
			on error errText number errNum
			"Timed out: " & errText
			
			-- not much we can do here
			end try
			
		end repeat
		
		-- restore iTunes state
		if wasplaying = 1 then
			tell application "iTunes" to play
		end if
		
	end tell
	
end tell

If you want to completely automate alarm sending, you can set an alarm in iCal (maybe a recurrent one) and have it execute the script to notify the event. Of course, you will have to leave your Mac running if you want it to be able to send alarms.

Disclaimer

This procedure involves a lot of software components and lots of things might go wrong. There's no guarantee that it will work for you, nor that your Mac will not burst in flames in the process.

Cristian Draghici
09 Dec 2005