Unity 3D – Android – Native Microphone – JavaScript
How to access Android Microphone.
Record and Play
Hierarchy> Main camera> Inspector> Add Component
– ‘Audio Listener’
– ‘Audio Source’ setup:
– ‘Mute ‘ -> uncheck
– ‘Play On Awake’ -> uncheck
– ‘Loop’ -> uncheck
– ‘GetAudio.js’
#pragma strict function Start() { } function OnGUI() { if (GUI.Button(Rect(10,10,60,50),"Record")) { //static function Start(deviceName: string, loop: bool, lengthSec: int, frequency: int) audio.clip= Microphone.Start ( null, false, 3, 44100 ); } if (GUI.Button(Rect(10,70,60,50),"Play")) { // play audio clip you have just recorded audio.Play(); } }
How does it work?
1. if you will touch GUI.Button(Rect(10,10,60,50),”Record”
2. it records an audio clip of 3 seconds, ONLY one time, no loop (static function loop: bool -> false)
3. if you will touch GUI.Button(Rect(10,70,60,50),”Play”
4. it plays the audio clip you have just recorded, ONLY one time, no loop, because into Inspector>’Audio Source’ component is set to ‘Loop’ -> uncheck
Record – > Effects -> Play
Super Easy! You need only attach audio filters components to ‘Audio Source’.
Hierarchy> Main Camera> Inspector> ‘Add Component’> Audio> Audio Echo Filter, setup the filter
Inside Hierarchy you will see:
Main Camera>
– ‘Audio Listener’
– ‘Audio Source’ setup:
– ‘Mute ‘ -> uncheck
– ‘Play On Awake’ -> uncheck
– ‘Loop’ -> uncheck
– ‘Audio Echo Filter’
– ‘GetAudio.js’
#pragma strict function Start() { } function OnGUI() { if (GUI.Button(Rect(10,10,60,50),"Record")) { //static function Start(deviceName: string, loop: bool, lengthSec: int, frequency: int) audio.clip= Microphone.Start ( null, false, 3, 44100 ); } if (GUI.Button(Rect(10,70,60,50),"Play")) { // play audio clip you have just recorded audio.Play(); } }
Record -> Chipmunks Voice -> Play
Hierarchy> Main camera> Inspector> Add Component
– ‘Audio Listener’
– ‘Audio Source’ setup:
– ‘Mute ‘ -> uncheck
– ‘Play On Awake’ -> uncheck
– ‘Loop’ -> uncheck
– ‘Pitch’ -> 1.58
– ‘GetAudio.js’
Record -> Satan Voice -> Play
Hierarchy> Main camera> Inspector> Add Component
– ‘Audio Listener’
– ‘Audio Source’ setup:
– ‘Mute ‘ -> uncheck
– ‘Play On Awake’ -> uncheck
– ‘Loop’ -> uncheck
– ‘Pitch’ -> 0.69
– ‘Audio Echo Filter’
– ‘GetAudio.js’