Text-To-Speech for in-game audio using existing audio files

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

Hi,

So, I have a bunch of audio files of a voice actor saying the letters of the alphabet and other sounds that could be compiled together to form a sentence with text to speech. However, I do not know how to code something like this or if it is even possible in Godot. Google is not helping and pretty much refuses to understand what I’m asking no matter how I write it so I was wondering if anyone knew how to code this.

I basically want to tell the engine to read out a sentence I have typed into the script with this voice made from these existing audio files. If this is possible please provide code or a link to a tutorial explaining it. Thank you. :slight_smile:

-YuleCrow

:bust_in_silhouette: Reply From: DONOTJUDGEMYCODE

Sorry for not including any code but if you have a decent understanding of GDScript I think you’ll be able to do this.

What you could do is just loop through all the characters, and check which sound to use. For instance:

You give the computer the phrase “Hello world”
It detects and breaks it up into the following pairs of letters:
“He”, “l”, “lo”, " ", “w”, “or”, “l”, “d”
It then plays the according sound for each pair.

Of course, I would recommend storing the valid pairs in a dictionary like this:

const PAIRS = {
     "He": "res://sounds/speech/he.mp3",
     "l": "res://sounds/speech/l.mp3",
     and so on...
}

If you need code of course I can supply it.

Hope this helps!

Ah, thank you. This makes a lot of sense. Do you think I could do this with similar code to a music controller autoload? The dictionary could be used in that code. I’m not sure how I’d get it to play the audio files one after the other rather than at the same time though.

YuleCrow | 2022-01-31 18:06

If you are using an AudioStreamPlayer node (which I recommend), you can use the finished() signal, which might look something like this:

on_AudioStreamPlayer_finished():
    canPlayNextAudio = true

DONOTJUDGEMYCODE | 2022-02-01 15:16

DONOTJUDGEMYCODE can you please supply the code for this tts system for me (i do not have the best knolage of gdscript)

thanks
kiwi_kid24

kiwi_kid24 | 2022-10-29 19:12