Forum rules - please read before posting.

Stoping Narrator speech audio track in sync with text ending.

Hi there, this is my first post here, I am having trouble trying to get this to work, so let me explain what I want to do:
_
I have two types of speakers in my game, one is the Narrator (Gabriel Knight style, no avatar or portrait to it) and the other, the Player and NPCs (with portraits) - While the player and NPC do talk and have Voice Overs, for the Narrator: I wanted to to fill this blank with a "speech audio" Nintendo-game style that plays per-letter (meaning, everytime a character text displays a sound plays)
_

Here´s how i have set up right now

This works OK, but I want to take it a step further by placing an AudioClip for it that sounds like a Typewritter (the current sound is too arcady for the game). Thing is, the typewriter sound is sometimes longer than the text (depends of the text and the description of the hotspot) so it keeps sounding sometimes although the text has finished showing.

Question is... how can I make the sound stop in sync with the text finalization? **
**Acclaration:
the text for the narrator scrolls, it does not show in one go

I guess the solutions comes from sending an Event Triggering on the text finalization that "ends" the AudioClip

Also, I would prefer to use a Prefabv AudioSource for this, sicne that way it allows me to pair it to an AudioMixer.

Hope i explained myself OK...

Thanks very much in advance!

Comments

  • Welcome to the community, @Sound_power.

    The text-scroll audio is more intended for smaller audio clips (e.g. a single beep or typewriter press sound) rather than a longer clip that might play only a single instance throughout the life of the speech line.

    When such audio is played for the narrator, it comes from the Scene Manager's "Default Sound" object. If you hook into the OnStopSpeech custom event, you can stop this sound from playing when narration ends:

    using UnityEngine;
    using AC;
    
    public class NarratorAudioStopper : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStopSpeech += StopSpeech; }
        private void OnDisable () { EventManager.OnStopSpeech -= StopSpeech; }
    
        private void StopSpeech (Char speakingCharacter)
        {
            if (speakingCharacter == null)
            {
                // Narration line
                KickStarter.sceneSettings.defaultSound.audioSource.Stop ();
            }
        }
    
    }
    

    The speech system provides a number of such events - see the Manual's "Speech scripting" chapter for details. As such, it's also possible to unset the Speech Manager audio field, and instead rely on your own custom audio system entirely:

    using UnityEngine;
    using AC;
    
    public class NarrationAudio : MonoBehaviour
    {
    
        public AudioSource narrationAudioSource;
        public AudioClip narrationAudioClip;
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech_Alt += StartSpeech;
            EventManager.OnStopSpeech_Alt += StopSpeech;
        }
    
        private void OnDisable ()
        {
            EventManager.OnStopSpeech_Alt -= StopSpeech;
            EventManager.OnStartSpeech_Alt -= StartSpeech;
        }
    
        private void StartSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == null)
            {
                narrationAudioSource.clip = narrationAudioClip;
                narrationAudioSource.Play ();
            }
        }
    
        private void StopSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == null)
            {
                narrationAudioSource.Stop ();
            }
        }
    
    }
    
  • Hi Chris! Thanks for responding to this, I am not really a coder myself, I can do stuff through visual scripting though, that´s why I use AC.

    I kinda get what you want me to do, guess I need to make this as scripts right? But what then?

    Some sort of steps might help me here.

  • edited August 2022

    The two scripts I wrote are variants of the same idea - don't try both at once, but one at a time.

    When adding a C# script file, you'll need to match the filename to the script's class name - i.e. the word after "class" to the top.

    For the first script, this'll need to be placed in a C# file named NarratorAudioStopper. Paste this in such a file, and you can then drag-drop it onto a new empty GameObject in your scene.

    When present in the scene, it will cause your scene's "Default Sound" object (which is where narration audio should be coming from) to stop playing when narration lines end.

    This may be enough for what you need, so let me know how you get on with that before trying out the second script, which would be named NarrationAudio.

  • Will try it soon, thanks Chris! :)

  • edited August 2022

    Hey Chris, both scripts worked great! But I am afraid that they don´t do what´s intended, the (longer) AudioClip of the typewriter now stops when the menu for the Narrator Speaker turns off, that´s better yes. But what I need is for it to stop when the text itself that´s displayed inside the menu reaches it´s end.

    What happens now it´s the AudioClip keeps sounding even though the text reached it´s ending ...

    Maybe I wasn´t clear the first time, sorry for that... not sure if this would help but here´s an screenshot.

    The purpose of this is to have the typewriting SFX accompany the Narrator text, but it loses credibility if it´s still sounding after the text has finished displaying.

    Thanks anyway!

  • You can hook into the OnCompleteSpeechScroll event instead, in that case:

    using UnityEngine;
    using AC;
    
    public class NarratorAudioStopper : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnCompleteSpeechScroll += OnCompleteSpeechScroll; }
        private void OnDisable () { EventManager.OnCompleteSpeechScroll -= OnCompleteSpeechScroll; }
    
        private void OnCompleteSpeechScroll (Char speakingCharacter, string speechText, int lineID)
        {
            if (speakingCharacter == null)
            {
                // Narration line
                KickStarter.sceneSettings.defaultSound.audioSource.Stop ();
            }
        }
    
    }
    

    See the Manual's "Speech scripting" chapter for a list of all available speech-related events.

  • That one worked perfectly! Thanks

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.