Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Snarky on Tue 21/11/2017 22:27:52

Title: Find length of speech clips?
Post by: Snarky on Tue 21/11/2017 22:27:52
Is there some way to find out from within AGS how long a certain speech clip is, without playing it?

Here's why I'm asking:

When you call Character.Say() with a voice clip (e.g. player.Say("&14 This line has voice-over");), the speech lasts as long as the clip, logically enough. (Depending on your Speech.SkipStyle setting the text may stay on screen longer, but the character won't do the Talk animation.)

However, if you set your Speech.VoiceMode to eSpeechTextOnly, the voice clip is ignored, and it seems the game falls back to using the standard AGS formula for how long to display the text, based on the string length and  Game.TextReadingSpeed.

I want to be able to maintain the same timing whether or not speech is turned on. If I could get the length of the speech clip I could do that (writing my own little function to manually do the Talk animation and time it correctly).
Title: Re: Find length of speech clips?
Post by: Ali on Fri 29/06/2018 16:29:50
Just bumping this, because I want to know the same thing - for background speech using a speech bubble module.
Title: Re: Find length of speech clips?
Post by: Crimson Wizard on Fri 29/06/2018 16:57:27
No, there is no way to do this in AGS script, unless your speech is made as regular audio clips (which I guess would be very inconvenient?).

EDIT:
We know that Audio Channel #0 is reserved for the voice speech. This probably means that you could test if System.AudioChannels[0] is currently playing to know if a voice-over is playing.
Perhaps this may be utilized somehow?
Title: Re: Find length of speech clips?
Post by: Khris on Fri 29/06/2018 22:48:19
Wouldn't it be possible to fake the eSpeechTextOnly setting and set the volume of Channel #0 to the lowest value, i.e. mute it?
Title: Re: Find length of speech clips?
Post by: Snarky on Sat 30/06/2018 06:23:41
Quote from: Crimson Wizard on Fri 29/06/2018 16:57:27
No, there is no way to do this in AGS script, unless your speech is made as regular audio clips (which I guess would be very inconvenient?).

For background speech you would have to do this anyway, since playing a speech clip is always blocking. So I'm not quite sure I follow what Ali is doing.

For what I wanted it for, on the other hand, I needed to be able to rely on that blocking.

Quote from: Crimson Wizard on Fri 29/06/2018 16:57:27
We know that Audio Channel #0 is reserved for the voice speech. This probably means that you could test if System.AudioChannels[0] is currently playing to know if a voice-over is playing.
Perhaps this may be utilized somehow?

Clever idea, but as said, when speech is played on audiochannel 0 the game blocks anyway. The problem is that with eSpeechTextOnly, the clip doesn't play at all.

Quote from: Khris on Fri 29/06/2018 22:48:19
Wouldn't it be possible to fake the eSpeechTextOnly setting and set the volume of Channel #0 to the lowest value, i.e. mute it?

Hmm, that might actually work for me. Although it would presumably fail if the audio clip couldn't play (voice pack not available or audio system not initialized, but that causes a lot of other problems in AGS anyway).
Title: Re: Find length of speech clips?
Post by: Ali on Sat 30/06/2018 23:31:10
Quote from: Snarky on Sat 30/06/2018 06:23:41
For background speech you would have to do this anyway, since playing a speech clip is always blocking. So I'm not quite sure I follow what Ali is doing.

I can't believe I hadn't noticed that SayBackground doesn't allow audio! In that case there's all the more reason to want to call a particular speech clip from script. I only have a handful though, so I'll just workaround.
Title: Re: Find length of speech clips?
Post by: Crimson Wizard on Sat 30/06/2018 23:59:34
Quote from: Ali on Sat 30/06/2018 23:31:10
I can't believe I hadn't noticed that SayBackground doesn't allow audio! In that case there's all the more reason to want to call a particular speech clip from script. I only have a handful though, so I'll just workaround.

The workaround is perhaps to move them to Sounds type and play as regular AudioClip.
The only problem would be to make playback consistent with voice settings in your game (volume etc).
Title: Re: Find length of speech clips?
Post by: Crimson Wizard on Thu 24/08/2023 23:41:17
Quote from: Crimson Wizard on Sat 30/06/2018 23:59:34The workaround is perhaps to move them to Sounds type and play as regular AudioClip.
The only problem would be to make playback consistent with voice settings in your game (volume etc).

Sorry for bumping this again, but I thought I should do this after receiving notifications that my answers here were "liked".

The information here is obsolete. Since AGS 3.5.0 (released about a year after this thread) there's Game.PlayVoiceClip() that lets you play a voice clip freely whenever you like, and adjust its playback properties just like with regular clips:
https://adventuregamestudio.github.io/ags-manual/Game.html#gameplayvoiceclip