Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 TheTurkeydipking · Jul 25, 2015 at 12:28 PM · audiomicrophonerecording

Unity 5 and using a microphone

Hey everyone, been losing my mind with this. What I'm trying to do is have the player hold the space button, and while its being held his voice is recorded. So as soon as the player lets go of space, that ends the recording, and the resulting audio clip is of the length that the player held the space button. This clip will then be used to analyze the volume vs. a set value, but for now I simply cannot figure out how to get this recording to work. The Microphone.Start function specifically wants an int value for length of recording. Any help would be greatly appreciated, as information on this topic seems rather sparse. Thanks in advance!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by zach-r-d · Jul 25, 2015 at 01:40 PM

Unfortunately, the only way to do this with the current API is a huge pain since resizing AudioClips isn't allowed:

  1. When space is pressed, call Microphone.Start(), passing some maximum length of time for a recording as the length. Start a real-time timer of some sort.

  2. When space is released, call Microphone.End(), and stop the timer.

  3. If the maximum length was reached, use it as is. Otherwise, continue on:

  4. Create a new array of size clip.frequency*clip.channels*realTimedSeconds.

  5. Call GetData() on the clip with the array and an offset of 0.

  6. Create a new AudioClip using AudioClip.Create with the same sample rate and number of channels, and with number of samples equal to the length of the array.

  7. Call SetData() on the new clip with the array and an offset of 0.

  8. Destroy the old clip.

  9. Return the new clip.

Tested with 5.1.2f1.

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 TheTurkeydipking · Jul 25, 2015 at 02:03 PM 0
Share

Thank you so much for your answer! It's a shame all this microphone stuff is such a mess in Unity :/ Would you by any chance know how the check the dB of the created audio clip? The goal is to have the player scream something and check how loud it is compared to "x" value? I suppose the GetOutputData might have something to do with it but I'm completely lost :/

avatar image zach-r-d · Jul 25, 2015 at 08:28 PM 0
Share

For that, it's probably best to just use the array with all the sample data in it acquired with GetData. $$anonymous$$ight not even need to create the second clip at all unless it's going to be played back later. The floats in the array are in the range [-1,1] and operate basically on a linear volume scale, so a sample at -1 OR 1 is at -0 dB, whereas a sample at 0 is at -inf dB. I'm not entirely sure how to convert between linear and dB, though.

But it could be that linear volume works for your needs, anyway. Try looping through the array to find the maximum value of a sample. It'll be between 0 and 1. 0 means perfect silence, 1 means the maximum volume the mic can handle without clipping.

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

22 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 avatar image avatar image avatar image avatar image

Related Questions

Delay with Microphone.Start 1 Answer

Guys i need help with audio! 0 Answers

Voice Recording issue ?? 0 Answers

Microphone Failed Result=33 0 Answers

Desynchronization of Gameplay with recorded Audio 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