Forum rules - please read before posting.

Best way to deal with character sound bytes?

Hi all,
I don't have full dialogue speech per-say but I do have 1-2 second sound bytes that play every now and then in dialogue speech for each character. Do I treat them as small sound effects? Or do something with them like you would do with speech?

Thanks for reading :)

Comments

  • With the randomness of how often a sound plays, and which sound is played, it's a case of using a custom script to hook into the OnStartSpeech custom event to decide what to do at the time the character it's attached to speaks:

    using UnityEngine;
    using AC;
    
    public class RandomSpeechBites : MonoBehaviour
    {
    
        public AudioClip[] speechBites;
        public Char speaker;
        [Range (0f, 1f)] public float playFrequency = 0.5f;
    
        private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech -= StartSpeech; }
    
        private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            if (speaker == null || Random.Range (0f, 1f) > playFrequency)
            {
                return;
            }
    
            if (speakingCharacter == speaker)
            {
                int index = Random.Range (0, speechBites.Length);
                AudioClip speechBite = speechBites[index];
                speaker.speechAudioSource.PlayOneShot (speechBite);
            }
        }
    
    }
    
  • Thank you so much Chris! This is awesome!
    I also wanted to ask, what's the best way I can optimize these sound files? They are small but should I still put them in SavableData for speech audio like recommended in the manual for speech?

  • They don't need to be stored in save-files - keep them out of Resources.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.