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.
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.
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 ?
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
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.
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.
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;
}
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.