• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TTS from Java on MacOS

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say -v '?' Gave an error message at the command line.

 
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bd Howard
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic