Mic Input

'''ATTENTION! THE JAVASCRIPT VERSION WILL NO LONGER BE UPDATED! THE LATEST UPDATED VERSION CAN BE FOUND ON The AssetStore'''

Hello my name is Mark Duisters and I came across allot of people having problems with getting audio from the machines microphone.

I have made a ready to use script, just place it on an empty GameObject and you are good to go.

from external scripts:

Call MicInput.loudness to get the audio data in a float format. (this can be used for scaling objects, chaning color, etc...).

Call gameObject.Find("MicInput").SendMessage("StopMicrophone"); This will terminate any data coming trough the mic in-game.

Call gameObject.Find("MicInput").SendMessage("StartMicrophone"); to start the mic from an external script (you don't need to call this as it is already running by default).

Note! StartMicrophone can only be called in the start function of a script (as that is the point where the mic is selected).

To use this script across all languages place it in the standard assets folder (not your own asset folder).

You are free to use this script under the creative commons restriction policy handled by the unify community.

This script can also be downloaded from the asset store under the name Mic Control (still pending for clearance).

Note that some functions are script depended, for instance the java version does not have a push to talk option.

Update Log:

1.2

C#

- Added 3 Talking methods: ~ Hold To Talk: Hold down a button to activate the mic. ~ Push To Talk: Press a button once to activate the mic, and press it again to stop it. ~ Constant Talk: The microphone will constantly be activated. - Improved the GUI functionality built into the script. - Editor GUI now shows which mic you are using. - General Optimization and bug fixes

1.1

- Fixed some bugs pointed out by djfunkey from the community: http://forum.unity3d.com/members/118660-djfunkey - Expanded the editor functionality: now you can choose the audio device which you want to use. Up to 6 devices are supported. If no device is found at the selected slot then the script will spit out an error message. - Added ShowDeviceName toggle. If true it wil print the device name and slot number to the console. - C# version of the script by djfunkey - Changed naming of several inputs to be more clear. - Added Source volume selection.(converted from djfunkey). - Added ingame menu (selected by user whether he wants to use it or not).(converted from djfunkey). - Added memory cleaning to prevent audio lag, both in java and C#(djfunkey).

UnityScript (java) features:

1: An Editor menu and an ingame menu so the user/player can pick the microphone they wish to use (handy if hey have a web-cam microphone, and a headset microphone).

2: The user can now adjust the volume of their microphone, it will also affect the loudness variable proportionally.

3: If there is only 1 device detected it will make that device default.

4: Call input data from any script trough MicInput.loudness.

5: Option for showing all device names in the console + debugging option for visually reading the input data.

6: Option to listen to your audio input by toggling the mute button.

Example: var Myfloat:float=MicInput.loudness; This could be used to detect when a player is speaking, breathing or to implement interactive environments. Good luck and have fun.

djfunkey did an excelent job in converting the script to C#. Thanks to him even more people can take advantage of the microphone in game. http://forum.unity3d.com/members/118660-djfunkey

The Editor Script for the C# version is below.


 * To talk in game using either of the methods press "T"*

C# features:

1: A menu so that the user can pick the microphone they wish to use (handy if hey have a web-cam microphone, and a headset microphone)

2: The user can now adjust the volume of their microphone, it will also affect the loudness variable proportionally.

3: The user can choose from 3 settings: PushtToTalk, HoldToTalk, ConstantTalk. These determine what the user has to do for the microphone to be activated.

4: If there is only 1 device detected it will make that device default.

5: Call microphone data from any script with MicrophoneInput.loudness.

6: The microphone RAM will still be flushed even if Time.timeScale = 0;

7: You can set how often the michrophone RAM is flushed.