From 2b6a8ffba2129d6f7ae7313375200f9906ce51df Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Fri, 10 Jul 2026 21:58:03 -0400 Subject: [PATCH] rbutil: Get rid of all remnants of SAPI4 TTS support Change-Id: I89cc53e2ebea273752c119e8c63f7eb36b1f22e0 --- tools/sapi_voice.vbs | 204 +++++++++-------------------- utils/rbutilqt/base/rbsettings.cpp | 1 - utils/rbutilqt/base/rbsettings.h | 1 - 3 files changed, 65 insertions(+), 141 deletions(-) diff --git a/tools/sapi_voice.vbs b/tools/sapi_voice.vbs index f39be986d0..4d81eda4a6 100644 --- a/tools/sapi_voice.vbs +++ b/tools/sapi_voice.vbs @@ -37,12 +37,11 @@ Const STDERR = 2 Dim oShell, oArgs, oEnv Dim oFSO, oStdIn, oStdOut -Dim bVerbose, bSAPI4, bList +Dim bVerbose, bList Dim bMSSP Dim sLanguage, sVoice, sSpeed, sName, sVendor Dim oSpVoice, oSpFS ' SAPI5 voice and filestream -Dim oTTS, nMode ' SAPI4 TTS object, mode selector Dim oVoice ' for traversing the list of voices Dim nLangID, sSelectString @@ -59,142 +58,78 @@ Set oEnv = oShell.Environment("Process") bVerbose = (oEnv("V") <> "") Set oArgs = WScript.Arguments.Named -bSAPI4 = oArgs.Exists("sapi4") bMSSP = oArgs.Exists("mssp") bList = oArgs.Exists("listvoices") sLanguage = oArgs.Item("language") sVoice = oArgs.Item("voice") sSpeed = oArgs.Item("speed") +' Create SAPI5 object +If bMSSP Then + Set oSpVoice = CreateObject("speech.SpVoice") +Else + Set oSpVoice = CreateObject("SAPI.SpVoice") +End If +If Err.Number <> 0 Then + WScript.StdErr.WriteLine "Error " & Err.Number _ + & " - could not get SpVoice object." _ + & " SAPI 5 not installed?" + WScript.Quit 1 +End If -If bSAPI4 Then - ' Create SAPI4 ActiveVoice object - Set oTTS = WScript.CreateObject("ActiveVoice.ActiveVoice", "TTS_") - If Err.Number <> 0 Then - Err.Clear - Set oTTS = WScript.CreateObject("ActiveVoice.ActiveVoice.1", "TTS_") - If Err.Number <> 0 Then - WScript.StdErr.WriteLine "Error - could not get ActiveVoice" _ - & " object. SAPI 4 not installed?" - WScript.Quit 1 - End If - End If - oTTS.Initialized = 1 - - If bList Then - ' Just list available voices for the selected language - For Each nLangID in LangIDs(sLanguage) - For nMode = 1 To oTTS.CountEngines - If oTTS.LanguageID(nMode) = nLangID Then - WScript.StdErr.Write oTTS.ModeName(nMode) & "," - End If - Next - Next - WScript.StdErr.WriteLine - WScript.Quit 0 - End If - - ' Select matching voice - For Each nLangID in LangIDs(sLanguage) - sSelectString = "LanguageID=" & nLangID - If sVoice <> "" Then - sSelectString = sSelectString & ";Speaker=" & sVoice _ - & ";ModeName=" & sVoice - End If - nMode = oTTS.Find(sSelectString) - If oTTS.LanguageID(nMode) = nLangID And (sVoice = "" Or _ - oTTS.Speaker(nMode) = sVoice Or oTTS.ModeName(nMode) = sVoice) Then - sName = oTTS.ModeName(nMode) - If bVerbose Then - WScript.StdErr.WriteLine "Using " & sName & " for " & sSelectString - End If - Exit For - Else - sSelectString = "" - End If - Next - If sSelectString = "" Then - WScript.StdErr.WriteLine "Error - found no matching voice for " _ - & sLanguage & ", " & sVoice - WScript.Quit 1 - End If - oTTS.Select nMode - - ' Speed selection - If sSpeed <> "" Then oTTS.Speed = sSpeed - - ' Get vendor information - sVendor = oTTS.MfgName(nMode) - -Else ' SAPI5 - ' Create SAPI5 object - If bMSSP Then - Set oSpVoice = CreateObject("speech.SpVoice") - Else - Set oSpVoice = CreateObject("SAPI.SpVoice") - End If - If Err.Number <> 0 Then - WScript.StdErr.WriteLine "Error " & Err.Number _ - & " - could not get SpVoice object." _ - & " SAPI 5 not installed?" - WScript.Quit 1 - End If - - If bList Then - ' Just list available voices for the selected language - For Each nLangID in LangIDs(sLanguage) - sSelectString = "Language=" & Hex(nLangID) - For Each oVoice in oSpVoice.GetVoices(sSelectString) - WScript.StdErr.Write oVoice.GetAttribute("Name") & ";" - Next - Next - WScript.StdErr.WriteLine - WScript.Quit 0 - End If - - ' Select matching voice +If bList Then + ' Just list available voices for the selected language For Each nLangID in LangIDs(sLanguage) sSelectString = "Language=" & Hex(nLangID) - If sVoice <> "" Then - sSelectString = sSelectString & ";Name=" & sVoice - End If - Set oSpVoice.Voice = oSpVoice.GetVoices(sSelectString).Item(0) - If Err.Number = 0 Then - sName = oSpVoice.Voice.GetAttribute("Name") - If bVerbose Then - WScript.StdErr.WriteLine "Using " & sName & " for " & sSelectString - End If - Exit For - Else - sSelectString = "" - Err.Clear - End If + For Each oVoice in oSpVoice.GetVoices(sSelectString) + WScript.StdErr.Write oVoice.GetAttribute("Name") & ";" + Next Next - If sSelectString = "" Then - WScript.StdErr.WriteLine "Error - found no matching voice for " _ - & sLanguage & ", " & sVoice - WScript.Quit 1 - End If - - ' Speed selection - If sSpeed <> "" Then oSpVoice.Rate = sSpeed - - ' Get vendor information, protect from missing attribute - sVendor = oSpVoice.Voice.GetAttribute("Vendor") - If Err.Number <> 0 Then - Err.Clear - sVendor = "(unknown)" - ' Some L&H engines don't set the vendor attribute - check the name - If Len(sName) > 3 And Left(sName, 3) = "LH " Then - sVendor = "L&H" - End If - End If - - ' Filestream object for output - Set oSpFS = CreateObject("SAPI.SpFileStream") - oSpFS.Format.Type = AudioFormat(sVendor) + WScript.StdErr.WriteLine + WScript.Quit 0 End If +' Select matching voice +For Each nLangID in LangIDs(sLanguage) + sSelectString = "Language=" & Hex(nLangID) + If sVoice <> "" Then + sSelectString = sSelectString & ";Name=" & sVoice + End If + Set oSpVoice.Voice = oSpVoice.GetVoices(sSelectString).Item(0) + If Err.Number = 0 Then + sName = oSpVoice.Voice.GetAttribute("Name") + If bVerbose Then + WScript.StdErr.WriteLine "Using " & sName & " for " & sSelectString + End If + Exit For + Else + sSelectString = "" + Err.Clear + End If +Next +If sSelectString = "" Then + WScript.StdErr.WriteLine "Error - found no matching voice for " _ + & sLanguage & ", " & sVoice + WScript.Quit 1 +End If + +' Speed selection +If sSpeed <> "" Then oSpVoice.Rate = sSpeed +' Get vendor information, protect from missing attribute +sVendor = oSpVoice.Voice.GetAttribute("Vendor") +If Err.Number <> 0 Then + Err.Clear + sVendor = "(unknown)" + ' Some L&H engines don't set the vendor attribute - check the name + If Len(sName) > 3 And Left(sName, 3) = "LH " Then + sVendor = "L&H" + End If +End If + +' Filestream object for output +Set oSpFS = CreateObject("SAPI.SpFileStream") +oSpFS.Format.Type = AudioFormat(sVendor) + Do aLine = Split(oStdIn.ReadLine, vbTab, 2) If Err.Number <> 0 Then @@ -211,19 +146,10 @@ Do aData = Split(aLine(1), vbTab, 2) If bVerbose Then WScript.StdErr.WriteLine "Saying " & aData(1) _ & " in " & aData(0) - If bSAPI4 Then - oTTS.FileName = aData(0) - oTTS.Speak aData(1) - While oTTS.Speaking - WScript.Sleep 1 - Wend - oTTS.FileName = "" - Else - oSpFS.Open aData(0), SSFMCreateForWrite, false - Set oSpVoice.AudioOutputStream = oSpFS - oSpVoice.Speak aData(1) - oSpFS.Close - End If + oSpFS.Open aData(0), SSFMCreateForWrite, false + Set oSpVoice.AudioOutputStream = oSpFS + oSpVoice.Speak aData(1) + oSpFS.Close Case "EXEC" If bVerbose Then WScript.StdErr.WriteLine "> " & aLine(1) oShell.Run aLine(1), 0, true diff --git a/utils/rbutilqt/base/rbsettings.cpp b/utils/rbutilqt/base/rbsettings.cpp index 4c4790c513..4e618ea01c 100644 --- a/utils/rbutilqt/base/rbsettings.cpp +++ b/utils/rbutilqt/base/rbsettings.cpp @@ -74,7 +74,6 @@ const static struct { { RbSettings::EncoderPath, ":encoder:/encoderpath", "" }, { RbSettings::EncoderOptions, ":encoder:/encoderoptions", "" }, { RbSettings::CacheDisabled, "cachedisable", "false" }, - { RbSettings::TtsUseSapi4, "sapi/useSapi4", "false" }, { RbSettings::EncoderNarrowBand, ":encoder:/narrowband", "false" }, { RbSettings::WavtrimThreshold, "wavtrimthreshold", "500"}, { RbSettings::TtsSpeed, ":tts:/speed", "175" }, diff --git a/utils/rbutilqt/base/rbsettings.h b/utils/rbutilqt/base/rbsettings.h index 55a4d8e4cf..a94486da20 100644 --- a/utils/rbutilqt/base/rbsettings.h +++ b/utils/rbutilqt/base/rbsettings.h @@ -70,7 +70,6 @@ class RbSettings : public QObject EncoderComplexity, TtsSpeed, CacheDisabled, - TtsUseSapi4, EncoderNarrowBand, EncoderQuality, EncoderVolume,