aspose file tools*
The moose likes Mac OS and the fly likes TTS from Java on MacOS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "TTS from Java on MacOS" Watch "TTS from Java on MacOS" New topic
Author

TTS from Java on MacOS

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

I've been playing with text to speech recently. After giving up on FreeTTS as more trouble than alternative approaches, I've been able to develop classes for the purpose for Windows (using a VBScript) and Linux, running in Sun VirtualBox (using a shell script and eSpeak) but I don't have access to, nor have ever so much as touched, a Mac. The Mac-specific code that follows is a cut-paste-edit of a full night's worth of Google searching. I took a look around, but I don't see any topics of this nature here.

This is not exactly a SSCCE, but it is as short as I could make it. If you have a Mac and a little time on your hands, feedback and bug fixes would be most welcome.
Thank you for reading.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Example use: (should work out-of-the-box on Windows XP and above, requires eSpeak to be installed for Linux).
http://www.fileden.com/files/2008/12/12/2221280/HousieGame.jar
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Copy and pasted. Ran and got
Voice `'?'' not found.


I then changed the "say" line to use an actual name rather than a question mark.

But then it hung because say requires a message.

This thread suggests looking in a directory for the list of available voices.

Jeanne-Boyarskys-MacBook-Pro:2012-cs258-testing nyjeanne$ ls /System/Library/Speech/Voices/
AgataCompact.SpeechVoice LeeCompact.SpeechVoice
Agnes.SpeechVoice MagedCompact.SpeechVoice
Albert.SpeechVoice MikkoCompact.SpeechVoice
Alex.SpeechVoice MilenaCompact.SpeechVoice
AylinCompact.SpeechVoice NaraeCompact.SpeechVoice
BadNews.SpeechVoice NarisaCompact.SpeechVoice
Bahh.SpeechVoice Organ.SpeechVoice
Bells.SpeechVoice OskarCompact.SpeechVoice
Boing.SpeechVoice PaoloCompact.SpeechVoice
Bruce.SpeechVoice Princess.SpeechVoice
Bubbles.SpeechVoice Ralph.SpeechVoice
Cellos.SpeechVoice RaquelCompact.SpeechVoice
DanielCompact.SpeechVoice SamanthaCompact.SpeechVoice
Deranged.SpeechVoice Sin-JiCompact.SpeechVoice
DiegoCompact.SpeechVoice StineCompact.SpeechVoice
EszterCompact.SpeechVoice Ting-TingCompact.SpeechVoice
FelixCompact.SpeechVoice Trinoids.SpeechVoice
Fred.SpeechVoice Vicki.SpeechVoice
GoodNews.SpeechVoice Victoria.SpeechVoice
Hysterical.SpeechVoice VirginieCompact.SpeechVoice
IdaCompact.SpeechVoice Whisper.SpeechVoice
JavierCompact.SpeechVoice XanderCompact.SpeechVoice
JoanaCompact.SpeechVoice Ya-LingCompact.SpeechVoice
Junior.SpeechVoice YannickCompact.SpeechVoice
Kathy.SpeechVoice Zarvox.SpeechVoice
KyokoCompact.SpeechVoice ZuzanaCompact.SpeechVoice


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Jeanne, thank you for trying the code.

Jeanne Boyarsky wrote:Copy and pasted. Ran and got
Voice `'?'' not found.

That's strange. I took that from the official reference. It's even in the examples towards the bottom of that page.

What does that do from the terminal, with and without the single quotes? I'm thinking the single quotes may require quoting or double-quoting when passed from Runtime.exec. There's one line in my Linux implementation that looks like this, I may need something similar here.

I then changed the "say" line to use an actual name rather than a question mark.

But then it hung because say requires a message.

Yes, that I would expect. But the purpose of that method is to retrieve a String array of available voice names (for subsequent use in a JComboBox).

Does this alternative, adapted from a MacScripter topc, work for you?

This thread suggests looking in a directory for the list of available voices.

That would be a last resort, capturing the 'ls' of that directory. Looks like the parsing needed, to get a voice name that can be passed to say, is to take the part up to the first dot and insert a space before each uppercase letter (except the first).

Thank you again.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Say -v '?' Gave an error message at the command line.

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Darryl,

I don't know if this will help you or not, but in Terminal, if I type:

say -v bruce hello my name is bruce

the computer speaks in the Bruce voice: hello my name is bruce

If I type only "say -v bruce" at the beginning then hit enter, I get the beach ball spinning for a few seconds, then whatever I type at the prompt is spoken in the bruce voice once I hit the enter key. Each phrase I have it speak is on one line in the Terminal.

Perhaps this is already known to you, but maybe not.

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I ran your first code, and changed the ? to a name like Jeanne did. I stepped it to the while loop that read from the Scanner instance, which ended up being a null reference.

I pasted in your new code, and the terminal output read:

Voice: Ralph Volume: 61

and got a Null pointer in the try block at scripFile.getAbsolutePath() in the speak method.

Hope that helps. :-)

BD
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Thank you, Howard. Should I conclude that the man page for say is in error? Or am I looking at a page that's for a version later than that you're testing on?

edit Oh, I see that say -v '?' appears for ver. 10.7.4 and isn't there for 10.6.

What about the second option, the one uising NSSpeechSynthesizer? Does that fly?
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Far be it from me to declare a manual in error. I just typed some stuff into Terminal and reported to you what happened. :-)

I am running Lion. I did not consult the manual, just typed in a few commands to test how "say" worked.

If you want me to test something specific, just ask. :-)

Cheers

BD
 
 
subject: TTS from Java on MacOS