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
1
Question by JJks · Aug 09, 2012 at 12:01 PM · audioaccessrealtimemicrophone

How do I get audio data from microphone in realtime?

Unity 3.5.2 OS windows 7 64bit

I want to develop applications with my microphone. Is it possible to access real time audio data from microphone? Actually I can access audio data, but below my code occurs 1 sec latency. Are there any ways?

 void Start ()
 {
     audio.clip = Microphone.Start(Microphone.devices[0], true, 1, 44100);
     audio.Play();
 }

 void Update ()
 {
     AudioListener.GetOutputData(samples, 0);
     float sum = 0.0f;
     for(int i=0; i 
     // Bunny83: Indent your code by 4 spaces
     // UA has stripped a part of your code because you started
     // a HTML tag with the lower-than char. edit your question and add
     // the rest of your code. You can remove this comments of course ;)
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
0

Answer by Bunny83 · Aug 09, 2012 at 12:44 PM

You can actually never get Mic-data in realtime. The hardware needs some time to sample the data. Also Unity reads in blocks of data. Unlike when playing an audio-file you can't read into the future. I'm not sure if you can reduce the buffer size somewhere, but the latency will never disappear completely.

Comment
Add comment · Show 1 · 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 zombience · Feb 05, 2013 at 03:16 PM 0
Share

I don't $$anonymous$$d a bit of latency, but is this a viable method? If I can get latency down to 50ms I'd be happy for the moment. Are there other solutions to this problem, such as using f$$anonymous$$od and OnAudioFilterRead ?

I need to do some live audio input, and while latency isn't ideal, it's obviously going to be a factor, so I'll deal with a little bit

Thanks

avatar image
0

Answer by PicklesIIDX · Aug 27, 2014 at 06:40 AM

I've been playing with this and I noticed that if I called Microphone.Start() in Awake, I would get a ton of latency, but sometimes not. I put the call in Start() and now I have almost no latency.

Comment
Add comment · Show 1 · 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 JelmerV · Jun 12, 2018 at 01:05 PM 0
Share

Thanks for this. $$anonymous$$y iOS app would crash/hang all the time on

  while (!($$anonymous$$icrophone.GetPosition(null) > 0)){}

until I moved initialisation to Start (from Awake).

avatar image
0

Answer by mcpepa · Dec 02, 2015 at 09:50 AM

this could help. there is a little delay, its normal. be carefull with the reverb that is made between the audio intput and the audio output.

 void Start()
     {
         AudioSource aud = GetComponent<AudioSource>();
         aud.clip = Microphone.Start(null, true, 1, 4400);
         aud.loop = true;
         while (!(Microphone.GetPosition(null) > 0)){}
         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

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

12 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

Related Questions

Playing SuperCollider realtime through audio sources 0 Answers

Record Audio for triggering something 0 Answers

Deleting an AudioClip created by the microphone 0 Answers

Capture audio without playing it back 2 Answers

Voice Recording issue ?? 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