Tuesday, 25 December 2012

Stage 4: Authoring


Action Script 2.0 is used for this interactive Installation Art Piece. The script will detect the microphone as input. The volume level by the users is divided into 4 categories. Each category will trigger 2 random different heartbeat sounds as the output. When voice is detected, the script will stop detecting the voice until the heartbeat sound is finished played. This is to avoid too many outputs happen at 1 time and affect the art piece.
Below is the script:

//declare a boolean variable to toggle mic on and off
var micToggle:Boolean = true;
onEnterFrame = function() {
                //if true on the mic, if false off the mic
                if (micToggle == true) {
                                myMic = Microphone.get();
                                attachAudio(myMic);
                                myMic.setUseEchoSuppression(true);
                                micOn.text="You can speak now..."
                                //trace("on");
                } else {
                                delete myMic;
                                micOn.text="Please wait..."
                                //trace("off");
                }
                //trace(myMic.activityLevel);
                if (myMic.activityLevel>60 && myMic.activityLevel<70) {
                                detectLevel.text="Level 1"
                                //trace("level 1");
                                micToggle = false;
                                randomVar = random(10);
                                //trace(randomVar);
                                if (randomVar<=5) {
                                                mySound = new Sound();
                                                mySound.attachSound("1.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 1";
                                                //trace("play sound 1");
                                } else {
                                                mySound = new Sound();
                                                mySound.attachSound("2.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 2";
                                                //trace("play sound 2");
                                }
                                delay1 = function () {
                                                micToggle = true;
                                                //trace("yes");
                                };
                                setTimeout(delay1,3000);
                } else if (myMic.activityLevel>70 && myMic.activityLevel<80) {
                                detectLevel.text="Level 2"
                                //trace("level 2");
                                micToggle = false;
                                randomVar = random(10);
                                //trace(randomVar);
                                if (randomVar<=5) {
                                                mySound = new Sound();
                                                mySound.attachSound("3.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 3";
                                                //trace("play sound 3");
                                } else {
                                                mySound = new Sound();
                                                mySound.attachSound("4.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 4";
                                                //trace("play sound 4");
                                }
                                delay2 = function () {
                                                micToggle = true;
                                                //trace("yes");
                                };
                                setTimeout(delay2,3000);
                } else if (myMic.activityLevel>80 && myMic.activityLevel<90) {
                                detectLevel.text="Level 3"
                                //trace("level 3");
                                micToggle = false;
                                randomVar = random(10);
                                //trace(randomVar);
                                if (randomVar<=5) {
                                                mySound = new Sound();
                                                mySound.attachSound("5.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 5";
                                                //trace("play sound 5");
                                } else {
                                                mySound = new Sound();
                                                mySound.attachSound("6.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 6";
                                                //trace("play sound 6");
                                }
                                delay3 = function () {
                                                micToggle = true;
                                                //trace("yes");
                                };
                                setTimeout(delay3,3000);
                               
                } else if (myMic.activityLevel>90 && myMic.activityLevel<100) {
                                detectLevel.text="Level 4"
                                //trace("level 4");
                                micToggle = false;
                                randomVar = random(10);
                                //trace(randomVar);
                                if (randomVar<=5) {
                                                mySound = new Sound();
                                                mySound.attachSound("7.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 7";
                                                //trace("play sound 7");
                                } else {
                                                mySound = new Sound();
                                                mySound.attachSound("8.mp3");
                                                mySound.start();
                                                soundSample.text="Sample 8";
                                                //trace("play sound 8");
                                }
                                delay4 = function () {
                                                micToggle = true;
                                                //trace("yes");
                                };
                                setTimeout(delay4,3000);
                }
};