How to play a sound synched with a typewritter effect in a richtextlabel effect?

Godot Version

4.3

Question

I have this script for a bbcode effect that types out each character in a richlabel and I wanted to modify it so that a sound would play each time a character is typed. I don’t really understand richlabel custom effect code that well (I copied this script from reddit) and have been looking over the docs for a couple hours but still don’t really get it. Here’s the code:

The audio in this code has many instances all playing on top of another at the beginning of the effect then stops immediately after. Also not sure if this could also be adding to the problem but the method I’m using to play the audio is this:

I’m using this because I was having some trouble getting the audio to play directly in code and found this script which worked

I’m not sure where the code is from, but from what I can tell, on line 13, the code is expecting a path to the sound you want to have played.

var sfx: String = char_fx.env.get("sfx", "path/goes/here")

Replace “path/goes/here” with the path to your sound effect. You can do this by right clicking on the sound you want to have played inside your project, and clicking on “Copy Path” then pasting it in between those quotes. See if that does it.

the path to the sound is provided in the text string itself for example:

this string would be put into a richtextlabel “[type][type sfx=path/to/sound] text goes here[/type]”

the bbcode script then takes the path and loads it as an AudioStream. Which then plays every single frame for whatever reason

my problem is that I can’t get it to play in time with the typewritter effect revealing each letter then stopping once all text has been revealed.