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 eguels · Apr 14, 2015 at 03:26 PM · audioaudioclipmicrophone

Microphone input to Audio Clip.

Hi,

Does anyone know how to get Unity to play back a microphone input in real time? I've managed to get it record an audio clip and then play it back on demand, but no methods I've used will make it play back real-time, it will either make an inaudible chopped noise, or an infinite feedback loop.

Please help, I'm getting desperate here!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by eguels · Apr 14, 2015 at 10:20 PM

Update: I figured it out, it now works. Here's the code:

     function Start () {
         var aud = GetComponent.<AudioSource>();
         aud.clip = Microphone.Start("Built-in Microphone", true, 10, 44100);
         aud.loop = true;
         while (!(Microphone.GetPosition(null) > 0)){}
         aud.Play();
     }
 function Update () {
 
 }

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 TheFloatingSheep · Apr 14, 2015 at 08:55 PM

First thing... without headphones you will can't do that.

Ok, so: You probably tried this:

 function Start() {
     var aud = GetComponent.<AudioSource>();
     aud.clip = Microphone.Start("Built-in Microphone", true, 10, 44100);
     aud.Play();
 }

You need a delay there so try this instead:

 function Start() {
     var aud = GetComponent.<AudioSource>();
     aud.clip = Microphone.Start("Built-in Microphone", true, 10, 44100);
     // \/
     yield WaitForSeconds(1);
     aud.Play();
 }

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 topher217 · Aug 03, 2017 at 06:56 AM

@eguels

Can you explain what this bit is doing and why it is necessary?

 while (!(Microphone.GetPosition(null) > 0)){}

I just added that and it solved a lot of my problems! Thank you very much. Just wanting to understand why it is necessary, and why the only reference I've found to such a fix is a 0-voted comment in the forums :S .

Comment
Add comment · Show 4 · 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 Polystorm · Aug 03, 2017 at 07:16 AM 0
Share

I'm glad it helped you! IIRC, I never knew what it did. Even now, I can't quite figure it out. In hindsight, it shouldn't do anything at all - even though there's a condition, the curly brackets are empty.

avatar image topher217 Polystorm · Aug 03, 2017 at 07:30 AM 0
Share

Ha, alright. I guess you found it in some other forum code?

Yes, I also did not understand why it affects anything, which is why I was so stumped after comparing with it in and then commenting it out...there was an OBVIOUS difference....BUT fiddling with this 5-$$anonymous$$ later, and commenting it out changes nothing now...looks like this wasn't actually what fixed my problem...I'm stumped again, but at least its working now... elusive bugs.

avatar image zeng_william5 Polystorm · Mar 05, 2018 at 07:13 AM 0
Share

This means: when computer detect a sound(maybe all silence mark with null), it will jump out loop and play it?

avatar image n8allan · Jul 07, 2018 at 04:29 AM 1
Share

The long answer is that you can't read directly from the analog to digital converter in a non-realtime OS, so there will always be some level of buffering before data becomes available in order for the audio data to be stable. Once the internal buffers fill to some threshold, data becomes available and this can be deter$$anonymous$$ed by checking that the microphone position has begun to advance. I would recommend a coroutine rather than a while {}. As written this will introduce a freeze or glitch during the initial buffering.

avatar image
0

Answer by imranmouna · Sep 25, 2017 at 04:27 PM

@eguels Thanks for posting this, I have been struggling with this problem for a long time. Unfortunately when I tried your solution I still get a very noticeable delay (about 1 second) between when I say something and when I hear it through my headset. Is that to be expected? I'm not using the wait function shown in the other answer.

Thanks in advance for any help

Comment
Add comment · Show 3 · 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 Polystorm · Sep 25, 2017 at 08:45 PM 0
Share

I'm glad you've found this helpful, but unfortunately, I did not find a way to reduce the delay, which was also quite horrible in my case too.

avatar image topher217 · Sep 26, 2017 at 12:51 AM 1
Share

I haven't tested it extensively, and delays are not such a big issue with what I'm dealing with, but you might want to try the "Superpowered" library. It has an example Unity scene so you might be able to test it out fairly quickly with what you are trying to do.

http://superpowered.com/incredible-incredibly-fast-audio-library

avatar image imranmouna · Sep 26, 2017 at 03:08 AM 0
Share

Okay cool thanks, I'll check it out and let you know how it goes.

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

9 People are following this question.

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

Related Questions

Microphone Position goes larger than predetermined number of samples 0 Answers

Multiple Microphone Inputs 0 Answers

Microphone capture different channels 0 Answers

How to record audio in chunks and send through websocket? 0 Answers

Is it possible to select channels for the microphone input? 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