Is it possible to make an speech detection with Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gamemap

When I say a command, the program should execute a function.
(If I say “Increase health” a function run to Increase my health.)

Is that possible? (with Godot?)

:bust_in_silhouette: Reply From: IHate

Sure you just need to parse the sentence you have entered.
There is multiple ways and it depends on the amount of control you need for something simple you don’t even need the “Increase Health” use “health” and a positive or negative value to reduce it. If you want more control and other functionalities appart from increasing and decreasing I recommend using symbols between the action and the subject examples:
This way you can use split("symbol") to get both ends of the command line separated you can use spaces too with " " but bear in mind you may be using spaces in the name of objects or other things so It may create problems.

var text = "set_level: 20" 
text[0] = "set"
text[1] = "level: 20"

If the command was set_level_20  
text[2] = "20"

text_entered() from a lineEdit node signal.

var command = text.split("_")[0]
var subject = text.split("_")[1]
var parameter = text.split(":")[1]    #use " " for a space separation

match command:

If you use a custom resource or a dictionary you can do something like this:

var stats :dictionary = {health:50,level:2}

func increase(subject,parameter):
stats.subject += int(parameter)  #param was parsed as a string so change it to an int

If you don’t use dictionaries or resources you can use match again writing every possible variable you want to modify but this would take a lot of space I don’t recommend it if you are thinking of adding more than a couple of things.

func increase(subject,parameter):

match subject:
    health += parameter
    level += parameter
    exp += parameter

I don’t want to make this too long but there’s all kind of things you can make to improve this for example what happens if you want to modify something that’s not a stat or if you want to use multiple parameters make the command line case insensitive, etc, etc.

Thanks for this answer, but how can I detect what is being said into a microphone?
Sorry that I have expressed myself in a misleading way.

Gamemap | 2021-03-09 08:34

I don’t think Godot has that functionality you would have to implement it yourself and once you successfully pick the sentence from the microphone and turn it into a String then you can do I what I wrote above.

IHate | 2021-03-09 08:49

Ok, I will try to make this.
Thank you.

Gamemap | 2021-03-09 09:25

:bust_in_silhouette: Reply From: MRimmer

This repository may be of some help:

With its tutorial here:

If my understanding is correct, after setting it up as described, you do do something like:

func _process(delta):
    if not queue.empty():
        string = queue.get()
        if string == "test":

Yes, that is what I am looking for. Thank you!

Godot will maybe add something like this.(#983)

Gamemap | 2021-03-09 15:12