Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Breaking out of a Shell
#1
I'm trying to use a stripped-down version of the shell Text To Speech sub that was posted some time ago...

Sub speak (message As String)
    Shell _Hide "Powershell -Command " + Chr$(34) + "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('" + message + "');" + Chr$(34)
End Sub

... and it works very well.
But I want to use it to speak the instructions for a game, which has several short paragraphs, and I want the user to be able to halt the speech after
any paragraph and return to the game. I've tried using a few variants of _Keyhit>0 and Inkey$<>"" but none seems to be recognized while the speech is in progress, presumably because I'm still in Shell. Any suggestions on how to do this (simply) would be appreciated. Huh
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
Once it starts shelling and speaking, it pushes your text to speech into a buffer and won't quit until it speaks it all fully for us.

It sounds like the only way to do what you want is to break down the speaking so it speaks per line, instead of per paragraph, and check for keypresses between those speak statements.

Speak "Hello there brave adventurer."
CheckForInput
Speak "This is the end of the world and you are the hero in these dark times.
CheckForInput
Speak "If you don't save the world...."
CheckForInput
Speak "Well, the world will probably just end!!!"
CheckForInput
Reply
#3
For a non-Shell approach I use a speech synthesizer app to save voice-overs to separate files in a folder. Then for example when you _SndPlay VoiceOver5 you can always check for user input to stop it: 

If _SndPlaying(VoiceOver5) _AndAlso input$ = "s" Then _SndStop VoiceOver5

or you could put all the VOs in an array and set up a loop to check if any voice-overs are playing and shut em down...

If input$ = "s" Then
     For a = 0 to UBound(VoiceOver)
     If _SndPlaying(VoiceOver(a)) Then _SndStop VoiceOver(a): Exit For
     Next
End If
Reply
#4
(07-02-2025, 12:31 AM)SMcNeill Wrote: Once it starts shelling and speaking, it pushes your text to speech into a buffer and won't quit until it speaks it all fully for us.

It sounds like the only way to do what you want is to break down the speaking so it speaks per line, instead of per paragraph, and check for keypresses between those speak statements.

Speak "Hello there brave adventurer."
CheckForInput
Speak "This is the end of the world and you are the hero in these dark times.
CheckForInput
Speak "If you don't save the world...."
CheckForInput
Speak "Well, the world will probably just end!!!"
CheckForInput

Thanks Steve
This is what I thought I had done, but the Speak section was embedded in another sub, and I wasn't breaking out properly, I think.
I've re-constructed it correctly and done as you described, with If Inkey$<>"" Then Exit Sub , and it works correctly.
Thanks both for responding.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code locks up when SHELL paulel 4 259 02-15-2026, 08:04 PM
Last Post: madscijr
  Shell issues eoredson 7 1,315 05-10-2025, 02:59 AM
Last Post: eoredson
  Using shell to delete a file PhilOfPerth 7 1,509 04-25-2024, 05:04 AM
Last Post: PhilOfPerth
  Having trouble Windows command line SORT via SHELL GTC 19 4,366 08-26-2023, 04:19 AM
Last Post: GTC
  SHELL creates unicode file, can't read correctly with LINE INPUT thesolarcode 3 1,219 05-06-2023, 09:41 PM
Last Post: thesolarcode

Forum Jump:


Users browsing this thread: 1 Guest(s)