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.
There are no new questions, but there may be new answers.
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).
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).
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.
I've got just enough Java knowledge to royally screw everything up. :-)
Joined: Mar 30, 2012
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.