Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 zeri · Jul 16, 2013 at 04:25 PM · audioaudiosource

Play an AudioSource

Hi guys, i'm working on a script that register save and play audio from microphone.

I did almost all the only thing that i've to fix is the audio.Play();

this is my code:

 private var buttonWidth = Screen.width * 0.2;
 private var buttonHeight = Screen.width * 0.05;
 private var buttonX = Screen.width *0.01;
 private var buttonY = Screen.width *0.01;
 private var micIn : boolean = false;
 private var getAudioSource : AudioClip;
 private var deviceName : String;
 
 
 
 function Start() {
     if(Microphone.devices.Length <= 0){
         Debug.Log("Microphone not Connected");
     }else{
         micIn = true;
         for(var i : int = 0; i < Microphone.devices.length; i++){
             Debug.Log(Microphone.devices[i]);
             deviceName = Microphone.devices[i];
         }
     }    
 }
 
 function registerAudio() {
     Debug.Log("Recording Audio");
     getAudioSource = Microphone.Start(deviceName , false, 10, 44100);
 }
 
 function stopRecording(){
     Debug.Log("Stop Recording");
     Microphone.End(deviceName);
     
 }
 
 function saveAudio(){
     SavWav.Save("registerAudio", getAudioSource); 
 }
 
 function playAudio(){
     
     getAudioSource.Play(); 
 }
 
 function OnGUI(){
     if(micIn){
         if(!Microphone.IsRecording(deviceName)){
             if(GUI.Button(Rect(buttonX,buttonY, buttonWidth, buttonHeight), "Record")){
                 registerAudio();
             }
         }else{
             if(GUI.Button(Rect(buttonX, buttonY, buttonWidth, buttonHeight), "Stop Recording")){
                 stopRecording();
             }
         }
 
         if(GUI.Button(Rect(buttonX,buttonY+(buttonHeight*1.2), buttonWidth, buttonHeight), "PlayAudio")){
             playAudio();
         }
         
         if(GUI.Button(Rect(buttonX, buttonY+((buttonHeight*2)*1.2), buttonWidth, buttonHeight), "SaveAudio")){
             saveAudio();
         }
         
         if(Microphone.IsRecording(deviceName)){
             GUI.Label(Rect(buttonWidth +50, 10, buttonWidth, buttonHeight), "Recording");
         }else{
             GUI.Label(Rect(buttonWidth +50, 10, buttonWidth, buttonHeight), "Not Recording");
         }
     }
 }

Two things i found:

if i add to getAudioSource, where microphone register audio datas , .clip i can play it but then i can't save with SavWav class. there is any other way to play what i recorded without putting .clip to getAudioSource?

Comment
Add comment · Show 3
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 amphoterik · Jul 16, 2013 at 04:48 PM 0
Share

What do you mean you "can't"? Do you get an error message? Can we get more info?

avatar image zeri · Jul 16, 2013 at 05:48 PM 0
Share

Yes this is the message i get:

 $$anonymous$$issing$$anonymous$$ethodException: UnityEngine.AudioClip.Play
 Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.ProduceExtensionDispatcher ()
 Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.Create ()
 Boo.Lang.Runtime.RuntimeServices.DoCreate$$anonymous$$ethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
 Boo.Lang.Runtime.RuntimeServices.Create$$anonymous$$ethodDispatcher (System.Object target, System.String name, System.Object[] args)
 Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey14.<>m__7 ()
 Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.Dispatcher$$anonymous$$ey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
 UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
 audioRegisterTest.playAudio () (at Assets/Scripts/audioRegisterTest.js:40)
 audioRegisterTest.OnGUI () (at Assets/Scripts/audioRegisterTest.js:56)
 
avatar image zeri · Jul 17, 2013 at 09:33 AM 0
Share

No one can help me? Thanks

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Jul 17, 2013 at 01:54 PM

AudioClip doesn't have a Play method, but AudioSource do.

 private var getAudioSource : AudioClip;
 ...
 getAudioSource.Play(); // MissingMethodException: UnityEngine.AudioClip.Play
  

Comment
Add comment · Show 2 · 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 zeri · Jul 23, 2013 at 09:00 AM 0
Share

the problem is that if i want to use SavWav class i've to keep it as AudioClip and not AudioSource.

avatar image Statement · Jul 26, 2013 at 09:36 AM 0
Share

Yeah, but look at the docs for AudioSource, you can play clips with it.

avatar image
0

Answer by LemonLake · Jul 26, 2013 at 09:52 AM

You need to give the AudioSource an AudioClip to play, then call the Play() method on your AudioSource.

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.

Follow this Question

Answers Answers and Comments

18 People are following this question.

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

Related Questions

Audio not coming out of speakers 1 Answer

Can OnAudioFilterRead be used with WebGl 3 Answers

How to control scene lighting based on amplitude of AudioSource? 1 Answer

PlayClipAtPoint Qualify with Type Name 2 Answers

In-game sound turns off when I play 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