Text to Speech Options

cbell

New member
Trying several options to put text to speech in my exeoutput 2018 app using php 7.2.

I wanted to use the HTML5 Speech API, but it appears that CEF doesn’t support the Speech API without API keys, etc.

I tried compiling in the php_com_dotnet.dll extension and using
Code:
<?php
$voice = new COM(SAPI.SpVoice);
$voice->Speak("I like iced tea");
and while it works outside of ExeOutput, it throws an “unknown exception” in ExeOutput.

I found a little app called voice.exe that I tried to compile into the program and execute with
Code:
<?php
$path = exo_unpackvirtualfile('voice.exe', '');
echo $path;
echo exec($path . " \"I liked iced tea\"");
But nothing seems to be happening when that supposedly executes.

Does anyone have a working solution for text to speech in a ExeOutput application?
 
Last edited:
cbell said:
<?php $voice = new COM(SAPI.SpVoice); $voice->Speak(“I like iced tea”);
Tested the code outside ExeOutput and in a normal PHP environment. The same error occurs when Speak is invoked.
cbell said:
I found a little app called voice.exe that I tried to compile into the program and execute with
exec() isn’t able to run virtual EXE files.
You must follow the tutorial here:
“Run a program that was compiled in the application”
http://www.exeoutput.com/help/samplescriptrunexe#run-a-program-that-was-compiled-in-the-application
 
Last edited:
gdgsupport said:
Tested the code outside ExeOutput and in a normal PHP environment. The same error occurs when Speak is invoked.
To make it work outside of ExeOutput I changed to the directory “C:\Program Files (x86)\ExeOutput for PHP 2018\PHPRuntime72” and execute the following command
"php.exe -d extension=ext\php_com_dotnet.dll -r "$voice=new COM('SAPI.SpVoice'); $voice->Speak('hello world');"
gdgsupport said:
exec() isn’t able to run virtual EXE files.
You must follow the tutorial here:
“Run a program that was compiled in the application”
http://www.exeoutput.com/help/samplescriptrunexe#run-a-program-that-was-compiled-in-the-application
This method allows the program to run so that does seem to be an option. Thank you for your help.

For anyone wanting the voice.exe file I found it here voice.exe - easy command line text to speech
 
Last edited:
As a follow up here is the method I ended up using. The voice.exe method works, but there was a small lag whenever the voice.exe had to be launched.

I downloaded a free to use speech wrapper DLL from https://forum.unity.com/threads/text-to-speech-dll-for-windows-desktop.56038/page-4#post-3340957.

Using the x86 version of the DLL from the plugins folder, I added that to the root dir of my project and set it to unpack the file upon startup.

In my UserMain script I added the following functions
Code:
function Uni_Voice_Init: Integer; stdcall; external "SAPI_UNITY_DLL.dll";
function Uni_Voice_Speak(TextToSpeech: String): Integer; stdcall; external "SAPI_UNITY_DLL.dll";  
function Uni_Voice_Close: Integer; stdcall; external "SAPI_UNITY_DLL.dll"; 
procedure Speak(s: String);          
begin
    // when calling from javascript input is terminated at "/" character
    // so replace them with "~" and they will be put back here
    s := ReplaceString(s, "~", "/");    
    //MessageDlg(s, "The text", mtInformation, [mbOK]);  
    Uni_Voice_Speak(s);                                                
end;
In the existing function OnPubLoaded I added

Uni_Voice_Init();

and in OnPubBeingClosed I added

Uni_Voice_Close();

Now from javascript, I can do

exeoutput.RunHEScriptCom('UserMain.Speak|This is <emph>some<~emph> text!');

Notice I replaced the < /emph> with <~emph>. Something was truncating the string at the ‘/’ character so I changed it to a ‘~’ character and replace it in the Speak function.
 
Last edited:
Back
Top