• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GarrettJohnson · Jun 28, 2012 at 08:36 PM · soundaudioclipreverse

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by DarKKendO · Jan 23, 2013 at 10:16 PM

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 t$$anonymous$$s by doing somet$$anonymous$$ng like t$$anonymous$$s (not proper code) :

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

T$$anonymous$$s will set the sound to play from the end in reverse if you are at the start.

Hope t$$anonymous$$s helps :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Kiloblargh · Jun 28, 2012 at 10:29 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ADISKING1 · Aug 02, 2020 at 08:43 PM

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;
     }
 
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

"Cannot get/set data from streamed sample" from audioclip 1 Answer

Is OnAudioFilterRead Still the Preferred Method for Procedural Audio? 0 Answers

how to make multiple sound augmented reality in 1 scene UNITY? 0 Answers

Synch clips with BPM 2 Answers

How to get decibel's value of game's sound? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges