![]() |
|
Breaking out of a Shell - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Breaking out of a Shell (/showthread.php?tid=3790) |
Breaking out of a Shell - PhilOfPerth - 07-01-2025 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.
RE: Breaking out of a Shell - SMcNeill - 07-02-2025 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 RE: Breaking out of a Shell - NakedApe - 07-02-2025 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 RE: Breaking out of a Shell - PhilOfPerth - 07-02-2025 (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. 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. |