Play audio in reverse

I need to be able to play an audio clip backwards and change the speed of the audio smoothly between playing forwards and backwards.

Right now, I can smoothly increase the speed of the audio playback by increasing the pitch slowly, but as soon as I start get below zero, it stops playing. Is there a way to get audio to play in reverse?

No. Just have a second audio clip that is the first one reversed, and pause the forward one and start playing the reversed one at the reversed clip’s total time minus the forward clip’s elapsed time.

I was having the same problem but I managed to work around it. Your question is a little unclear however.

When the pitch gets below 0 the sound should play in reverse assuming that there is some clip left to play. If the time of the clip is at 0 then it cant reverse beyond the start.

I managed to get around this by doing something like this (not proper code) :

audioSource.pitch = playSpeed;
if (playSpeed < 0)
    audioSource.Time = audioSource.Clip.Length;

audioSource.Play();

This will set the sound to play from the end in reverse if you are at the start.

Hope this helps :slight_smile:

Temporary Fix I came up with

using System.Collections;
using UnityEngine;

public class AudioPlayer : MonoBehaviour
{
    private AudioSource audioSource;

    void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }

    public void PlayAudio(AudioClip audioClip)
    {
        audioSource.pitch = 1;
        audioSource.clip = audioClip;
        audioSource.Play();

    }
    public void PlayReverseAudio(AudioClip audioClip)
    {
        audioSource.pitch = -1;
        audioSource.loop = true;
        audioSource.clip = audioClip;
        audioSource.Play();
        StartCoroutine(StopLoop());
    }

    public IEnumerator StopLoop()
    {
        yield return new WaitForSeconds(1f);
        audioSource.loop = false;
    }

}