_Title "Steve's Powershell Speech Script"
SaP "Hello World, This is a normal speed demo of David's voice", "David", 0
SaP "Hello again. This is a normal speed demo of Ziva's voice.", "Ziva", 0
SaP "And now I'm speaking as David, but I'm speaking veeery slow.", "David", -10
SaP "And now I'm a very hyper Ziva!", "Ziva", 5
SaP "And now I'm done with my demo!", "", 0
Sub SaP
(text$
, who$
, speed
) speak text$, Speaker, speed
Static n: n
= n
+ 1 'This sets an incremental counter for our output file (Test1, Test2, Test3, ect) message = text
'some symbols and such can't be used with Powershell like this, as they're command symbols
'we need to strip them out of our text. (Like apostrophes!)
remove$
= "'" + Chr$(34) 'add to remove$ here, if more symbols need to be removed as future testing showcases problems out$
= "Powershell -Command " + Chr$(34) out$
= out$
+ "Add-Type -AssemblyName System.Speech; " out$
= out$
+ "$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer; " out$
= out$
+ "$Speech.SetOutputToWaveFile({" + Chr$(34) + "D:\Repo\qb64\Test" + _Trim$(Str$(n
)) + ".wav" + Chr$(34) + "}); " 'The command to send the output to a file and not the speakers. If Speaker
= 0 Then out$
= out$
+ "$Speech.SelectVoice('Microsoft David Desktop'); " If Speaker
= 1 Then out$
= out$
+ "$Speech.SelectVoice('Microsoft Zira Desktop'); " out$
= out$
+ "$Speech.Speak('" + message
+ "');" + Chr$(34)