Modifying UI Typewriter audio?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
wrigleybug
Posts: 2
Joined: Tue Sep 10, 2019 10:18 pm

Modifying UI Typewriter audio?

Post by wrigleybug »

Hello! I'm brand new to the Dialogue System and pretty new to code in general. I apologize if this is a silly question or if there's a much easier way to go about it!

I have Animal Crossing-esque "gibberish" speech that replaces the default typewriter sound (which is just one file played at a random pitch, instead of the "random audio clip" feature that's built in). Essentially: I'm interested in adding a variable to the UI Typewriter Effect that would let me set a custom pitch range for each character, while keeping the same audio file for all subtitles. That way I wouldn't need to have a separate file for each character, while still getting really varied voices for each character.

I understand the idea of how it should be done, but I'm a bit too new to coding to be able to make sense of what goes where with regards to the parent scripts. I'm not sure if Dialogue System itself has a better alternative to my idea, but I'm interested in any strategies. Thank you!
User avatar
Tony Li
Posts: 21636
Joined: Thu Jul 18, 2013 1:27 pm

Re: Modifying UI Typewriter audio?

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

You'll need to make a subclass of the typewriter effect (e.g., UnityUITypewriterEffect) and override the PlayCharacterAudio() method. Try this subclass:
CustomPitchTypewriterEffect.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CustomPitchTypewriterEffect : UnityUITypewriterEffect
{
    private float minPitch;
    private float maxPitch;

    public override void StartTyping(string text, int fromIndex = 0)
    {
        // Look up character's MinPitch and MaxPitch field values:
        var actorName = DialogueManager.currentConversationState.subtitle.speakerInfo.nameInDatabase;
        var actor = DialogueManager.masterDatabase.GetActor(actorName);
        if (actor.FieldExists("MinPitch"))
        {
            minPitch = actor.LookupFloat("MinPitch");
            maxPitch = actor.LookupFloat("MaxPitch");
        }
        else
        {
            minPitch = maxPitch = 1;
        }

        // Then do the regular StartTyping() method:
        base.StartTyping(text, fromIndex);
    }
    protected override void PlayCharacterAudio()
    {
        // Set a random pitch:
        audioSource.pitch = Random.Range(minPitch, maxPitch);

        // Then do the regular play audio:
        base.PlayCharacterAudio();
    }
}
I've also included it in this example scene so you can see how it works:

TypewriterPitchExample_2019-09-11.unitypackage

The comments in the script should hopefully explain what it does. It works similarly to the example in this post, except is uses a subclass of the typewriter effect script instead of a separate script that works in parallel with the typewriter. It still uses the same concept of defining the pitch range in the actor's definition in your dialogue database.

To set up the scene, I removed the original UnityUITypewriterEffect component and added the new script in its place.
User avatar
wrigleybug
Posts: 2
Joined: Tue Sep 10, 2019 10:18 pm

Re: Modifying UI Typewriter audio?

Post by wrigleybug »

Thank you so much, the amount of care put into answering this question is amazing!! I know I saw "incredible feedback" on the reviews for the system, but they really meant it. You guys are great!

This is exactly the kind of effect I was looking for, I just had no idea how to override the script (the gibberish sfx you included is hilarious also, it's great.) I'm delighted. Thank you again!!
User avatar
Tony Li
Posts: 21636
Joined: Thu Jul 18, 2013 1:27 pm

Re: Modifying UI Typewriter audio?

Post by Tony Li »

Happy to help! :-)
veeru
Posts: 1
Joined: Mon Jan 13, 2020 2:36 am

How can I add audio to the conversation

Post by veeru »

Hi there,
I can't add audio to my conversation.. am unable to find option for it. Can you please tell me how can I add audio to my conversation.
User avatar
Tony Li
Posts: 21636
Joined: Thu Jul 18, 2013 1:27 pm

Re: Modifying UI Typewriter audio?

Post by Tony Li »

Hi,

If you want to add audio such as voiceover to each dialogue entry (like in the Dialogue System's demo), use the AudioWait() sequencer command. You can learn more about sequences in the Cutscene Sequence Tutorials. The short answer is to: (1) Put your audio file in a Resources folder, and (2) Drag it into the dialogue entry's Sequence field. There are many more options, however; I recommend checking out the sequence tutorials.

If you want to add audio to the typewriter effect, drill down into the dialogue UI and assign it to the Subtitle Text's typewriter effect, in the Audio Clip and Alternate Audio Clip fields.
mel
Posts: 5
Joined: Thu May 30, 2024 11:43 am

Re: Modifying UI Typewriter audio?

Post by mel »

Hi Tony,

First off, I am really loving this asset (as well as Quest Machine). Thanks for creating a cool asset and continuing to offer support.

Just a quick question related playing audio at various pitches for different characters - do you have to define the min and max pitch outside of engine? I had a look at the example scene and could find no way in the scene or in the dialogue database interface to set these min and max pitch values for actors. I exported the example database and see the values in there, but as it's a pain to export/import to tweak these values, I just wanted to double check in case I was missing something.

I'm looking to implement a similar behaviour, where gibberish is played while the line is printing. All actors will draw gibberish from the same files, but play at their own pitch.

Thank you!
User avatar
Tony Li
Posts: 21636
Joined: Thu Jul 18, 2013 1:27 pm

Re: Modifying UI Typewriter audio?

Post by Tony Li »

Hi,

If you're looking at the example scene linked above, each actor's min/max pitch is set in the Dialogue Editor window's Actors section:

minMaxPitch.png
minMaxPitch.png (34.04 KiB) Viewed 740 times

In the example scene, I added these as custom fields in the Templates section.
mel
Posts: 5
Joined: Thu May 30, 2024 11:43 am

Re: Modifying UI Typewriter audio?

Post by mel »

Hi Tony, thank you so much! Didn't realize that existed since I haven't done much with actor customization yet. 😅 This solution will work great.
User avatar
Tony Li
Posts: 21636
Joined: Thu Jul 18, 2013 1:27 pm

Re: Modifying UI Typewriter audio?

Post by Tony Li »

Glad to help! If any questions come up, let me know.
Post Reply