Typewriter speed based on audio

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
OceaneM
Posts: 9
Joined: Thu Apr 27, 2023 11:08 am

Typewriter speed based on audio

Post by OceaneM »

Hello Tony,

I'd like the typewriter speed to be based on the length of the audio we play and the number of characters. Because depending on the language, or the content of the text, the speed might be quite different.
In my Entries I have a sequence with a custom AudioWait:

Code: Select all

public class SequencerCommandAudioWaitLength : SequencerCommandAudioWait
{
    protected override void TryAudioClip(string audioClipName)
    {
        base.TryAudioClip(audioClipName);
        if(currentClip!=null)
        {
            DialogueLua.SetVariable("voicelineLength", currentClip.length);
        }
    }
}
In my custom Typewriter I set the charactersPerSecond before the StartTyping method :

Code: Select all

    public override void StartTyping(string text, int fromIndex = 0)
    {
        float audioLength = DialogueLua.GetVariable("voicelineLength").asFloat;
        charactersPerSecond = textComponent.text.Length / audioLength;
        base.StartTyping(text, fromIndex);
    }
But I think the typewriter starts typing before the entry sequence starts. Do you have an idea to set the typewriter speed based on the audio length?

Thank you,
Océane
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Typewriter speed based on audio

Post by Tony Li »

Post Reply