Infinite Loop? Trying voice regognition and audio alerts.

Official forum for open source FreePIE discussion and development.
Post Reply
Thorixion
One Eyed Hopeful
Posts: 3
Joined: Thu Jun 20, 2019 9:11 am

Infinite Loop? Trying voice regognition and audio alerts.

Post by Thorixion »

I've been trying to make a script for Space Engineers to have multiple key layouts. It is supposed to switch AutoHotkey scripts every time I say a certain category (eg whether I want to fly or build) and play a sound so I don't strafe instead of using the jetpack. The problem is that FreePIE says that it found an infinite loop sometimes, but I used no loops within the code. It will also play the alert multiple times occasionally. Any help would be appreciated. Here is my code:

Code: Select all

import subprocess
from subprocess import call
import time
from time import sleep

def heard(vcmd, cfd):
	return speech.said(vcmd, cfd)

def play(audio_file_path):
    subprocess.call(["ffplay", "-nodisp", "-autoexit", audio_file_path])

if heard("normal", 0.2):
    call("C:\\ahkscripts\\sp_engr_c1.ahk", -1, None, None, None, None, None, False, True)         
    call("C:\\ahkscripts\\sp_engr_h1.ahk", -1, None, None, None, None, None, False, True)
    play("C:\\ahkscripts\\a.wav")

if heard("camera", 0.1):
    call("C:\\ahkscripts\\sp_engr_c2.ahk", -1, None, None, None, None, None, False, True)
    call("C:\\ahkscripts\\sp_engr_h2.ahk", -1, None, None, None, None, None, False, True)
    play("C:\\ahkscripts\\a.wav")

if heard("fly", 0.3):
	call("C:\\ahkscripts\\sp_engr_c3.ahk", -1, None, None, None, None, None, False, True)
	call("C:\\ahkscripts\\sp_engr_h3.ahk", -1, None, None, None, None, None, False, True)
	play("C:\\ahkscripts\\a.wav")

if heard("build", 0.3):
    
    call("C:\\ahkscripts\\sp_engr_c4.ahk", -1, None, None, None, None, None, False, True)        
    call("C:\\ahkscripts\\sp_engr_h4.ahk", -1, None, None, None, None, None, False, True)
    play("C:\\ahkscripts\\a.wav")
    
if heard("inventory", 0.0):
    keyboard.setPressed(Key.I)

if heard("jetpack", 0.0):
	keyboard.setKey(Key.X, not keyboard.getPressed(Key.X))

if heard("crouch", 0.0):
	keyboard.setKey(Key.Apostrophe, not keyboard.getPressed(Key.Apostrophe))

if heard("break through", 0.0):
	keyboard.setKey(Key.F, not keyboard.getPressed(Key.F))
GermanSani
One Eyed Hopeful
Posts: 12
Joined: Sun Feb 28, 2021 8:44 am

Re: Infinite Loop? Trying voice regognition and audio alerts.

Post by GermanSani »

Hi,

well, I couldn't find a solution unfortunately but the problem is, in my opinion, that the call()-function only ends, when you stop the program that's called by it. For as far as I have read this is because the call()-function always waits until the process it has started has terminated which is never the case here unless you do it manually. Reason for the Infinite-Loop-Error Message.

Unless there's a way to implement termination of AHK inside the AHK-scripts but I don't know much about that.

This also prevents from switching scripts on-the-fly, unless, again, there's a possiblity for that in AHK itself. Which however wouldn't solve the real problem.

I tried with the open()-function but that didn't work at all.
Maybe it works with the os.system("start " + Filename)-Command somehow but I had no luck with that either, I just had the same results.

Maybe this helps you at least a little bit.
Thorixion
One Eyed Hopeful
Posts: 3
Joined: Thu Jun 20, 2019 9:11 am

Re: Infinite Loop? Trying voice regognition and audio alerts.

Post by Thorixion »

Well, thanks for trying. Maybe I could send a key to ahk, in which case it would read the keystroke as a hotkey or in an if statement. I have added a bunch of simpler voice commands (eg setPressed), so now I only have to change between three layouts instead of four.
Post Reply

Return to “FreePIE”