How to run terminal or python in linux and retrive output using OS.execute?

Godot Version

4.3 stable

Question

I am making a desktop pet of sorts and for that want a text-to-speech for that. For that, I thought of two solutions: Either use Linux’s espeak in terminal or use python’s pyttsx3 for text to speech.
The problem I am facing is that I have no clue how to use OS.execute (primarily due to being relatively new in such kinds of things). I had read the documentations and seen some reddit posts about it but none of them worked for me.
The official documentation runs CMD.exe which, according to my knowledge should not be in Linux (due to it being .exe but maybe with wine) and one of the redit solution comments (3 years old) used python.exe (Same problem). I tried both of them but none worked.
A solution using the mint terminal would be much preferred compared to the python alternative (Which is obviously the python-plugin) as I would be using more such Linux processes.
Thanks!

The documentation is quite clear on how to use OS.execute() (the link should take you there). The rest isn’t really a godot specific problem, but you need to look into what commands to use for TTS. Once you have that, OS.execute simply expects you to supply that command with some optional parameters, and the documentation shows that off quite well!

I actually use this to generate levels for my game. The basic idea is:

func list_files() -> bool:
    var out = []
    var cmd = "/usr/ls"
    var args = [ "-l", "~/.local/share/godot" ]

    if OS.execute(cmd, args, out) != 0:
        return false

    print("Got:\n" + out)
    return true

Bear in mind that this blocks the thread it runs in, so if the command is going to take more than a fraction of a second you really want to run it in a separate thread.