Tech Tip: Cross Platform Text To Speech in 4D
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: June 1, 2018
Windows has a Text-To-Speech feature built-into Powershell.
MacOS has a Text-To-Speech feature called "Say".
The following method can be used on either platform to invoke the system specific Text To Speech mechanism:
C_TEXT($1;$cmd;$in;$out;$err) If (Count parameters=1) $textToSpeech:=$1 If (Folder separator=":") // mac $cmd:="say "+$textToSpeech Else //windows $cmd:="PowerShell -Command \"Add-Type –AssemblyName System.Speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('"+$textToSpeech+"');\"" End if SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true") SET ENVIRONMENT VARIABLE("_4D_OPTION_BLOCKING_EXTERNAL_PROCESS";"false") LAUNCH EXTERNAL PROCESS($cmd;$in;$out;$err) End If |
If the method is saved as TextToSpeech it could be used like this:
TextToSpeech("Wow, it actually works!") |