Play custom sound clip?

Original Discord Post by eggman28 | 2024-01-14 20:32:55

If I wanted a custom sound clip to be played when the avatar is asked a specific question, any thoughts as to how that could be done ? Can assume the sound clip can be embedded locally or streamed, whichever is easier. Am currently looking at Unity but could try UE if that works instead.

Reply by k3kalinix | 2024-01-14 20:49:12

Hello <@711465199001010298>

Reply by k3kalinix | 2024-01-14 20:52:37

In Unity, you can create an Action like this.

PlayAudio

Add what you want to do in the PlayAudio Method in the ActionsHandler script.
Since you are going to play audio, you should access the AudioSource reference and use the Play or PlayOneShot methods.

Then in the backstory you can add something like this.

When you are greeted: “Do the PlayAudio action”

Reply by k3kalinix | 2024-01-14 20:54:02

Now whenever you want to play a sound, specify it in the backstory.

Reply by eggman28 | 2024-01-14 20:55:41

Thanks for that ! Will try that out. And if I wanted it to be triggered by something more specific such as “When you are asked about ”, that should also work, is that right ?

Reply by k3kalinix | 2024-01-14 20:56:19

Yes

Reply by k3kalinix | 2024-01-14 20:56:42

You can check out sample backstories from the sample characters in the playground.

Reply by eggman28 | 2024-01-14 20:57:15

Amazing ! Thanks for the quick response ! Which sample should I look at for that ? You all have shared so many awesome samples :slightly_smiling_face:

Reply by k3kalinix | 2024-01-14 20:58:16

Images:


Reply by k3kalinix | 2024-01-14 20:58:17

Example

Reply by k3kalinix | 2024-01-14 20:58:47

I’m happy to help you.
If you have any other questions, please do not hesitate to ask.

We would be very grateful if you could leave a comment on our store pages with your company name or the name of your project. We value your feedback and comments as they help us improve our services and products.
Asset Store: NPC AI Engine - Dialog, actions, voice and lipsync - Convai | Behavior AI | Unity Asset Store

Embedded Content:
NPC AI - Dialog, actions and general intelligence - by Convai | Beh…
Get the NPC AI - Dialog, actions and general intelligence - by Convai package from Convai and speed up your game development process. Find this & other Behavior AI options on the Unity Asset Store.
Link: NPC AI Engine - Dialog, actions, voice and lipsync - Convai | Behavior AI | Unity Asset Store

Reply by eggman28 | 2024-01-14 21:00:03

Awesome ! Will have a closer look at those samples, thanks !

Replying to eggman28’s Message

Reply by eggman28 | 2024-01-14 21:00:03
Awesome ! Will have a closer look at those samples, thanks !

Reply by k3kalinix | 2024-01-14 21:00:32

You are welcome, don’t forget to write a review. :slightly_smiling_face:

Reply by eggman28 | 2024-01-14 21:00:39

Will do !

Reply by eggman28 | 2024-01-15 01:17:47

I’m trying a new project with the Asset Store package. I added this to my character’s backstory: ‘When you are asked to play the test: “Do the PlayAudio action”’
I updated the “ConvaiActionsHandler.cs” to have the PlayAudio action and selected it.
When I talk to my character asking for that, she replies with that text but doesn’t actually play the audio clip

I tried setting it to automatically play on awake to test that and it plays that way but not when asked for it.

Any pointers ? Thanks !

Images:


image.png

Reply by eggman28 | 2024-01-15 02:24:34

I also tried adding “When you are greeted: “Do the PlayAudio action”” to the backstory and I get greeted fine but can’t seem to trigger playing the audio.

Reply by eggman28 | 2024-01-15 02:33:01

Added the following to ConvaActionsHandler.cs and using Unity 2023.3.16f1:

    public AudioClip audioClip;
public AudioSource audioSource;

private void Start()
{

        //Load Audio Clip
        audioSource = GetComponent<AudioSource>();


}

    private void PlayAudio()
    {
        audioSource.PlayOneShot(audioClip);
    }

    private IEnumerator DoAction(ConvaiAction action)
    {
        // STEP 2: Add the function call for your action here corresponding to your enum.
        //         Remember to yield until its return if it is a Enumerator function.

        // Use a switch statement to handle different action choices based on the ActionChoice enum
        switch (action.Verb)
        {

            case ActionChoice.PlayAudio:
                // Call the PlayAudio function
                PlayAudio();
                break;

            case ActionChoice.None:
                // Call the AnimationActions function and yield until it's completed
                yield return AnimationActions(action.Animation);
                break;
        }

        // Yield once to ensure the coroutine advances to the next frame
        yield return null;
    }

Reply by eggman28 | 2024-01-15 04:29:15

Doing some debugging and it doesn’t look like I’m setting up that new action correctly as I’m seeing “actionResponse”: { “action”: “None” } in the console.
If I attach the PlayAudio to another action like “Move”, I can hear it play after she moves.

Reply by k3kalinix | 2024-01-15 04:30:06

I’ll help you as much as I can. What time zone are you in now?

Reply by eggman28 | 2024-01-15 04:30:28

I’m in AEST (Sydney, Australia)