- Home /
Microphone in 3.5 beta
Essentially I want to move an object based on the volume of the players voice (or failing that, simply move an object when the speaker is making noise) but I'm looking through the documentation on 'Microphone' and it's not great:
// Start recording with built-in Microphone and play the recorded audio right away
function Start() {
audio.clip = Microphone.startRecord("Built-in Microphone", true, 10);
audio.Play();
}
The above code is from the unity script reference for Microphone.Start and it's got a few problems. First, it's Microphone.Start not Microphone.startRecord and second it's suppose to have four arguments in it (string,boolean,int,int), not just three.
In short, the sample code doesn't work so I'm having trouble working from it.
So to reiterate, I want to be able to move an object based on the volume of the sound input in the microphone.
So is anyone having any luck with dealing with Microphone input in the 3.5 beta and if so could you please help start me off on coding this?
I tried fixing the example code but I'm not sure what to put in for the frequency, although anything above 0 works it doesn't seem to be doing anything (yes I have an audio source component on the scripted object and the camera/audio listener is close enough to hear things):
audio.clip = Microphone.Start(null, true, 10,??);
audio.Play();
Anyway, recording the audio is just half the problem, I need to analyze it on the fly, presumably using AudioClip.GetData in some fashion (not quite sure how I'd get the data for the part of the array that's currently being recorded though, among other things).
Anyway, any help would be greatly appreciated.
Bump. I am also doing something very similar.
I do have some microphone functionality working via a Obj-C plugin I found here http://goo.gl/t2Y2r. However this inhibits my ability to test with unity remote somewhat, and I feel as though the projects code is beco$$anonymous$$g fragmented.
Can you point me to the docs for the unity microphone class? I can't find it anywhere in the unity support pages... I feel as though this should be easy to find, but I don't see it anywhere.
I'd love to point you to the microphone class, but I don't have the docs anymore, I uninstalled the 3.5 beta a few days ago and reinstalled the most recent non beta release. However if you are running the beta you should just be able to search for '$$anonymous$$icrophone.Start' or something akin.
Answer by Linda · Jan 18, 2012 at 10:44 PM
Hi, I had a similar problem but i was able to fix it, by expanding you first fixing:
function OnGUI()
{
if (GUI.Button(Rect(10,10,60,50),"Record"))
{
// null graift auf das standart microfon des jeweiligen users zu
// soll nie Aufnahme geloopt werden (hier nciht -> false)
// Aufnahme Zeit in Sekunden (hier momentan 3)
// Aufnahme Fraquenz (hier 44100)
audio.clip= Microphone.Start ( null, false, 3, 44100 );
}
if (GUI.Button(Rect(10,70,60,50),"Play"))
{
//Aufnahme abspielen
audio.Play();
}
}
Thanks Linda, I see you figured out my problem with the frequency. I can't check this though since I uninstalled the 3.5beta but if it worked for you I'll give it a up vote.
We have mic input (no external code, just unity and C#) up and running on this thread, should be easy to use it for movement. http://forum.unity3d.com/threads/118215-Blow-detection-(Using-iOS-$$anonymous$$icrophone)
Your answer
Follow this Question
Related Questions
quickest way to read & write audio files with mic input? audio buffer? 0 Answers
How to get current gain from microphone? 1 Answer
Is it possible to record using Microphone.start and have non-fixed Audio clip length? 1 Answer
Extract pointer from Audioclip's buffer 0 Answers
Microphone recording problems (double sample, audiosource stops working) 0 Answers