0 votes

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?)

in Engine by (119 points)

2 Answers

0 votes
Best answer

This repository may be of some help:
https://github.com/menip/godot_speech_to_text

With its tutorial here:
https://samuraisigma.github.io/godot-docs/doc/community/tutorials/misc/speech_to_text.html

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":
            test()
by (120 points)
selected by

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

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

0 votes

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:
remove_health,invert-inventory,set/level...
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.split("_")
text[0] = "set"
text[1] = "level: 20"

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

Example:
text_entered() from a lineEdit node signal.

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

match command:
  "Increase":
    increase(subject,parameter)
  "Remove":
    remove(subject,parameter)
  "Set":
    set(subject,parameter)

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":
    health += parameter
  "level":
    level += parameter
  "exp":
    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.

by (388 points)
edited by

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.

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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.