#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Sun, 20 May 2018 10:07:55 +0200
changeset 22967 40423cdaeaa1
parent 22966 57d20ca389c1
child 22968 411d41553689
#REFACTORING by cg class: AbstractOperatingSystem class added: #voiceCommandSpec changed: #speak:voiceName:
AbstractOperatingSystem.st
--- a/AbstractOperatingSystem.st	Sun May 20 09:50:13 2018 +0200
+++ b/AbstractOperatingSystem.st	Sun May 20 10:07:55 2018 +0200
@@ -6607,24 +6607,68 @@
     "
 !
 
-speak:aString voiceName:aVoiceName
+speak:aString voiceName:voiceName
     "voiceName should be in the list of supported voices as returned by voiceInfo,
      or (better and portable) one of the keys in voiceMapping. 
      Use nil for the default voice (which is usually the user's preference voice setting in
      the operating system - eg. system preferences in OSX).
      For non-existing/unknown voiceNames, the default voice will be used.
 
-     Here, speak is unsupported and the system remains silent.
-     To be redefined in concrete subclasses."
-
-    ^ self.
-
-    "
-     OperatingSystem speak:'hello world'
-     OperatingSystem speak:'hello world' voiceName:'female'
-     OperatingSystem speak:'hello world' voiceName:'male'
-     OperatingSystem speak:'hello world' voiceName:'computer'
-    "
+     Here, looksfor one of the commands from voiceCommandSpec to be found
+     and call that external program for the speech generation.
+     Returns true if ok, false if not"
+
+    |mapping voiceUsed|
+
+    mapping := self voiceMapping detect:[:v | v key = voiceName] ifNone:[(voiceName -> voiceName)].
+    voiceUsed := mapping value.
+
+    self voiceCommandSpec triplesDo:[:cmd :cmdLineForDefaultVoice :cmdLineForVoice |
+        |cmdLine|
+        
+        (self canExecuteCommand:cmd) ifTrue:[
+            (voiceUsed isNil or:[voiceUsed = 'default']) ifTrue:[
+                cmdLine := cmdLineForDefaultVoice
+            ] ifFalse:[    
+                cmdLine := cmdLineForVoice
+            ].    
+        ] ifFalse:[
+            ^ self executeCommand:(cmd bindWith:voiceUsed with:aString withCEscapes).
+        ].    
+    ].
+    
+    "/ no command found.    
+    ^ false
+
+    "portable:
+     OperatingSystem speak:'hello world - this is the default voice' voiceName:nil
+     OperatingSystem speak:'hello world - this is a male voice' voiceName:'male'
+     OperatingSystem speak:'hello world - this is a female voice' voiceName:'female'
+     OperatingSystem speak:'hello world - this is a computer voice' voiceName:'computer'
+
+    non-portable (OSX only):     
+     OperatingSystem speak:'hello world - this is a scottish female voice' voiceName:'Fiona'
+     OperatingSystem speak:'hello world - this is a german female voice' voiceName:'Anna'
+     OperatingSystem speak:'hello world - this is a chinese female voice' voiceName:'Ting-Ting'
+     OperatingSystem speak:'hello world - this is an indian female voice' voiceName:'Veena'
+     OperatingSystem speak:'hello world - this is a french female voice' voiceName:'Amelie'
+     OperatingSystem speak:'hello world - this is an italian female voice' voiceName:'Alice'
+     OperatingSystem speak:'hello world - this is a russian female voice' voiceName:'Milena'
+
+     OperatingSystem speak:'hello world - this is a pipe organ speaking' voiceName:'Pipe Organ'
+     OperatingSystem speak:'hello world - happy birthday to you' voiceName:'Good News'
+    "
+!
+
+voiceCommandSpec
+    "commands to try for speech output"
+
+    ^ #(
+        "/ triples are:
+        "/      -command 
+        "/      -commandline for default voice
+        "/      -commandline for specific voice
+    )    
 !
 
 voiceInfo