Need Help Improving Glitchy Audio for a Puzzle Game

I’m working on a puzzle where each letter triggers a short audio, aiming for a smooth mechanical keyboard sound effect (sort of). How can I make this sound more smooth? I wanted to get sort of a mechanical keyboard sound effect. Any suggestions on how to make the sound more seamless and less glitchy?

private IEnumerator PlayAnimation()
      {
            animating = true;
            animating = true;
            int itemsIncluded = 4;

            for (int i = 0; i < _cipherSlotList.Count; i++)
            {
                  if (i >= itemsIncluded)
                  {
                        _cipherSlotList[i - itemsIncluded].StartSparkleAnimation(false);
                  }
                  _cipherSlotList[i].StartSparkleAnimation(true);
                  _cipherSlotList[i].StartLetterAnimation(true);

                  if (i % 2 == 0)
                        _cipherSlotList[i].PlaySound(); //play sound

                  yield return new WaitForSeconds(_timeBla);
            }
            for (int i = _cipherSlotList.Count - itemsIncluded; i < _cipherSlotList.Count; i++)
            {
                  _cipherSlotList[i].StartSparkleAnimation(false);
            }

            animating = false;
      }
 internal void PlaySound()
      {
            _soundController.PlaySound();
            _soundController.audioSource.pitch = UnityEngine.Random.Range(0.9f, 1.1f);
      }

I tried playing the sound of every second item, but that didn’t work. Also, audioSource.PlayOneShot doesn’t make difference. The only way I could smooth out things a little bit, is with pitching the audio with random values.

I’ve encountered this issue before (playing many short back to back audio clips) and there’s no one solution.

One possible approach could be to pool a few of the clips and play them async (so they overlap, rather than one cancelling another out)

Failing that (or on-top of)…

Better adjusting the animation speed to the audio. As a rough guess, each letter animation is about 80ms but the audio is nearly 250ms. So maybe slow the animation and trim some audio whitespace (as the animation\audio lag seems noticeable)

Just some ideas anyway :slight_smile:

Thanks! Will try it out today and let you know :slight_smile:

1 Like

Do you get the intended effect if you repeatedly press play in editor (without the pitch of course)?

@PeachyPixels idea would be mine as well, trim any unused audio space in your file to allow you to play it “quicker”.

Their advice on pooling is good too, when you type fast it might sound like you’re hitting multiple buttons async, otherwise it’ll sound glithy because the next clip wants to be played before the first one finishes naturally.

Another way around this is to record a longer clip of typing and using that longer audio clip, with modifiers, for the duration of the in game typing.

1 Like