FS#13972 - Improve rbutil SAPI5 stability (Alessio Lenzi)

The existing code treated any ready-read notification from cscript as
proof that synthesis had completed. The SAPI script can emit other
output, so the Utility could check for the wave file before the explicit
SYNC reply and report that the output file did not exist.

The script also used global "On Error Resume Next" without reporting
errors from SpFileStream.Open(), SpVoice.Speak(), or
SpFileStream.Close(). Several waits had no timeout, allowing the GUI
thread to remain blocked indefinitely.

The changes:

 * reports SAPI COM errors to Rockbox Utility;
 * verifies that SAPI actually created the requested wave file;
 * waits for the explicit SYNC reply instead of any process output;
 * applies finite timeouts to vendor queries, synthesis, and shutdown;
 * terminates a stuck private cscript process safely;
 * restarts cscript and retries the current string up to three times when a
   third-party SAPI engine stops responding during a long generation run.

Change-Id: I2cf2aefb704353c648bef0c4312f35282ac4e25d
This commit is contained in:
Solomon Peachy 2026-08-04 17:02:06 -04:00
parent 1b6767a7d7
commit a467bfc55f
2 changed files with 109 additions and 18 deletions

View file

@ -46,6 +46,7 @@ Dim oVoice ' for traversing the list of voices
Dim nLangID, sSelectString
Dim aLine, aData ' used in command reading
Dim nError, sError ' error returned to the controlling process
On Error Resume Next
@ -146,10 +147,27 @@ Do
aData = Split(aLine(1), vbTab, 2)
If bVerbose Then WScript.StdErr.WriteLine "Saying " & aData(1) _
& " in " & aData(0)
Err.Clear
oSpFS.Open aData(0), SSFMCreateForWrite, false
Set oSpVoice.AudioOutputStream = oSpFS
oSpVoice.Speak aData(1)
oSpFS.Close
nError = Err.Number
sError = Err.Description
If nError = 0 Then
Set oSpVoice.AudioOutputStream = oSpFS
oSpVoice.Speak aData(1)
nError = Err.Number
sError = Err.Description
oSpFS.Close
If nError = 0 And Err.Number <> 0 Then
nError = Err.Number
sError = Err.Description
End If
End If
If nError <> 0 Then
oStdOut.WriteLine "ERROR" & vbTab & nError & ": " & sError
Err.Clear
ElseIf Not oFSO.FileExists(aData(0)) Then
oStdOut.WriteLine "ERROR" & vbTab & "SAPI reported success but created no wave file"
End If
Case "EXEC"
If bVerbose Then WScript.StdErr.WriteLine "> " & aLine(1)
oShell.Run aLine(1), 0, true