Page 1 of 1

Typewriter speed based on audio

Posted: Wed Sep 27, 2023 10:26 am
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

Re: Typewriter speed based on audio

Posted: Wed Sep 27, 2023 2:32 pm
by Tony Li