Issue with making speech to text using python script and OS.execute

Godot Version

4.3

Question

I am trying to add speech to text to my game via running a python script, then getting the output with OS.execute. However, I get no output and the program crashes. Here is my godot code:
func _on_talk_button_pressed() → void:
var output =
var exit_code = OS.execute(“python3”, [PATHTOFILE], output, false)
print(“Exit code:”, exit_code)
print(“Output:”, output)

The python script continuously runs and outputs the words the microphone picks up. I feel the issue may have something to do with the fact that the python script doesn’t stop running by itself and just keeps listening, but I want it to run and the godot game at the same time.
I would be thankful for any help.

What do you mean by “the program crashes”? Does the game become unresponsive?

From the doc:

The main thread will be blocked until the executed command terminates. Use Thread to create a separate thread that will not block the main thread, or use create_process() to create a completely independent process.

Sounds like it is blocking, so you would need to either exit the Python program to return control to the game, or use it from a separate thread