Detective Time (itch) (Mattie) Mac OS

broken image


Bartender
posted 8 years ago
  • Optional 'thank-you' note:
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.import java.io.*; import java.util.*; public class MacSpeaker { protected File scriptFile; protected Process process; protected final String[] voices; protected int voiceIndex = 0; //protected int pitch = 0; // -10 to +10 protected int volume = 50; // 0 to 100 protected int rate = 100; // 80 to 400 public static void main(String[] args) { new MacSpeaker().test(); } private void test() { int numVoices = voices.length; if (numVoices 0) { return; } Random random = new Random(); for (int i = 0; i < 10 && i < numVoices; i++) { voiceIndex = random.nextInt(numVoices); volume = random.nextInt(100); System.out.println('Voice: ' + voices[voiceIndex] + ' Volume: ' + volume); speakAndWait('Hello World'); try { Thread.sleep(500); } catch (InterruptedException ex) { ex.printStackTrace(); } } } public MacSpeaker() { voices = populateVoiceArray(); } protected String[] populateVoiceArray() { Scanner input = null; try { Process p = Runtime.getRuntime().exec('say -v '?'); new ProcessReader(p, true); // consume the error stream input = new Scanner(p.getInputStream()); List<String> voiceList = new ArrayList<String>(); while (input.hasNextLine()) { voiceList.add(input.nextLine()); } return voiceList.toArray(new String[0]); } catch (IOException ex) { ex.printStackTrace(); } return new String[]{}; } protected void makeScriptFile() { String speakScript = ' + 'on run argvn' + ' set theCall to (item 1 of argv)n' + ' set theVoice to (item 2 of argv)n' + ' set theVolume to (item 3 of argv)n' + ' set theRate to (item 4 of argv)n' + ' set oldVolume to output volume of (get volume settings)n' + ' set volume output volume ((oldVolume * theVolume) / 100)n' + ' say -v theVoice -r theRate theCall with waiting until completionn' + ' set volume output volume (oldVolume)n' + 'end runn'; FileWriter fw = null; try { scriptFile = File.createTempFile('speech', '.scpt'); scriptFile.deleteOnExit(); fw = new java.io.FileWriter(scriptFile); fw.write(speakScript); } catch (IOException ex) { ex.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } public void speakAndWait(String call) { process = speak(call); if (process != null) { try { process.waitFor(); } catch (InterruptedException ex) { ex.printStackTrace(); } } } protected Process speak(String call) { process = null; try { process = Runtime.getRuntime().exec(new String[]{'osascript', scriptFile.getAbsolutePath(), '' + call + '', '' + voices[voiceIndex] + '', ' + volume, ' + rate }); new ProcessReader(process, false); // consume the output stream new ProcessReader(process, true); // consume the error stream } catch (IOException ex) { ex.printStackTrace(); } return process; } } class ProcessReader { public ProcessReader(Process process, final boolean errorStream) { final InputStream processStream = errorStream ? process.getErrorStream() : process.getInputStream(); new Thread() { @Override public void run() { try { BufferedReader br = new BufferedReader(new InputStreamReader(processStream)); String line; while ((line = br.readLine()) != null) { if (errorStream) { System.err.println(line); } else { System.out.println(line); } } } catch (IOException ex) { ex.printStackTrace(); } } }.start(); } }
Thank you for reading.

Compatible: Windows, Mac & Linux 64 bit. Ratings 'A well written 'big' adventure game that's fun to play. There's enough diversity within the game to hold the interest of most players.' 'B' rated on Just Adventure 'Demetrios is a superbly made game, the first in a long time that really had me hooked' Indie Game News. Available for Windows, macOS. WARNING: This game contains violence. It is a time of a vast empire. A warrior from the north has come to investigate a disappearance of a magistrate.

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

Bartender
posted 8 years ago
  • Optional 'thank-you' note:
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

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

author & internet detective
posted 8 years ago
  • Optional 'thank-you' note:
Copy and pasted. Ran and got

Detective Time (itch) (mattie) Mac Os 7


Voice `'?' not found.


I then changed the 'say' line to use an actual name rather than a question mark.
Process p = Runtime.getRuntime().exec('say -v Bruce');
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

[OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2

Bartender
posted 8 years ago
  • Optional 'thank-you' note:
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. + ' '' + call + ''

I then changed the 'say' line to use an actual name rather than a question mark.
Process p = Runtime.getRuntime().exec('say -v Bruce');
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?
Detective time (itch) (mattie) mac os 7
Detective time (itch) (mattie) mac os 7
protected String[] populateVoiceArray() { Scanner input = null; try { String voicesScript = ' + '#!/usr/local/bin/pythonn' + 'from AppKit import NSSpeechSynthesizern' + 'voices = NSSpeechSynthesizer.availableVoices()n' + 'for voice in voices:n' + ' voiceattr = NSSpeechSynthesizer.attributesForVoice_(voice)n' + ' voicename = voiceattr['VoiceName']n' + ' print voicename.encode('utf-8')n'; File file = File.createTempFile('voices', '.py'); file.deleteOnExit(); FileWriter fw = new FileWriter(file); fw.write(voicesScript); fw.close(); Process p = Runtime.getRuntime().exec('python ' + file.getPath()); new ProcessReader(p, true); // consume the error stream input = new Scanner(p.getInputStream()); List<String> voiceList = new ArrayList<String>(); while (input.hasNextLine()) { voiceList.add(input.nextLine()); } return voiceList.toArray(new String[0]); } catch (IOException ex) { ex.printStackTrace(); } finally { if (input != null) { input.close(); } } return new String[]{}; }

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

Detective Time (itch) (mattie) Mac Os Catalina

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.

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

author & internet detective
posted 8 years ago
  • Optional 'thank-you' note:
Say -v '?' Gave an error message at the command line.

[OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2

Greenhorn
posted 8 years ago
  • Optional 'thank-you' note:
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. :-)

Greenhorn
posted 8 years ago
  • Optional 'thank-you' note:
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

I've got just enough Java knowledge to royally screw everything up. :-)

Bartender
posted 8 years ago
  • Optional 'thank-you' note:
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?

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

Greenhorn
posted 8 years ago
  • Optional 'thank-you' note:
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

I've got just enough Java knowledge to royally screw everything up. :-) Damay mac os.

Change A Homeless Survival Experience Free Download Multiplayer 2019 PC Game With All Latest Updates And DLCs Mac OS X DMG 2019 GOG Repack Games Worldofpcgames.

Overview CAHE:

Change A Homeless Survival Experience is an motion recreation in addition to RPG simulation recreation. The recreation is all about to discover and uncover the brand new cities and a brand new life. The recreation is there to provide consciousness on the homeless points. There is a random metropolis within the recreation which the participant need to discover, uncover, survive. customization of the character can be vital recreation function. The recreation comprises many options. Exploring limitless cities within the recreation and every of them have totally different objects to discover and have distinctive setting to settle.

Survival is the principle recreation activity. The participant need to survive and make totally different methods to outlive. In each new metropolis the participant need to discover new residence, shelter, kindness and companion. It is upto the participant that how he get his home both by begging or performing some work. The meals and different eatables merchandise it's a must to discover to outlive. The participant additionally make totally different methods to face with excessive climate situations in each metropolis. Manage your fundamental wants which embrace hygiene, starvation, happiness and different. All this stuff it's a must to handle by your self.

Change A Homeless Survival Experience Free Download:

System Requirements

1 :: Operating System :: Windows 7 (64 Bit Processor)
2 :: Processor: 2.3 GHz
3 :: Ram :: 1 GB RAM
4 :: DirectX: Version 11
5 :: Graphics:: 256 MB Graphics Card
6 :: Space Storage:: 100 MB house





broken image