I don't think I understood what you want to achieve
i.e. how dialogue works in Undertale. How can I achieve a sync up between the dialogue sounds and the display of the characters? the rate the dialogue sounds play at seems somewhat arbitrary at the moment
you will have to merge this code into your dialogue system