Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:54:14+00:00 2026-06-03T01:54:14+00:00

How to record sound from a microphone and save it from the following code

  • 0

How to record sound from a microphone and save it from the following code

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
    <![CDATA[
        import flash.events.SampleDataEvent; 
        import flash.media.Microphone;
        import flash.net.FileReference;
        import mx.controls.Alert;
        import flash.net.FileReference;


        [Bindable] private var microphoneList:Array;
        protected var microphone:Microphone;
        protected var isRecording:Boolean = false;
        protected function setupMicrophoneList():void
        { 
            microphoneList = Microphone.names; 
        } 
        protected function setupMicrophone():void 
        {       
            microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
        } 
        protected function startMicRecording():void 
        { 
            Alert.show("In recording");
            isRecording = true;
            Alert.show("In recording1");
            microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
            Alert.show("In recording22");
        }
        protected function stopMicRecording():void 
        { 
            isRecording = false;
            microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
        } 
        private function gotMicData(micData:SampleDataEvent):void 
        { 
            Alert.show("In mic data");
            // micData.data contains a ByteArray with our sample. }
            try{
            var file:FileReference = new FileReference();
            file.save(micData.data ,"Testsound.flv");
            }
            catch(e:Error)
            {
                Alert.show("In gotomicdataexception"+e);
            }
        }

        ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ComboBox x="150" id="comboMicList" dataProvider="{microphoneList}" />
<mx:Button x="250" id="startmicrec" label="Start Rec" click="startMicRecording()"/>
<mx:Button x="350" id="stopmicrec" label="Stop Rec" click="stopMicRecording()"/> 
<mx:Button x="50" id="setupmic" label="Select Mic" click="setupMicrophone()"/>
<mx:Button x="450" id="playrecsound" label="Play sound" click="playbackData()"/>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:54:15+00:00Added an answer on June 3, 2026 at 1:54 am

    Here’s your updated code that will provide you ability to save file after recording it. But anyway you need to encode bytearray into format like wav or mp3:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   minWidth="955" minHeight="600"
                   creationComplete="this_creationCompleteHandler(event)">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
    
    
                [Bindable] private var microphoneList:Array;
                protected var microphone:Microphone;
                protected var isRecording:Boolean = false;
                private var soundBytes:ByteArray = new ByteArray();
                protected function setupMicrophoneList():void
                { 
                    microphoneList = Microphone.names; 
                } 
                protected function setupMicrophone():void 
                {       
                    microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
                } 
                protected function startMicRecording():void 
                { 
                    trace("In recording");
                    isRecording = true;
                    trace("In recording1");
                    microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
                    trace("In recording22");
                }
                protected function stopMicRecording():void 
                { 
                    isRecording = false;
                    microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
                    saveMicData();
                } 
    
                private function saveMicData():void
                {
                    trace("In mic data");
                    // micData.data contains a ByteArray with our sample. }
                    try{
                        var file:FileReference = new FileReference();
    
                        file.save(/*You need encoded soundBytes here*/soundBytes ,"Testsound.wav");
                    }
                    catch(e:Error)
                    {
                        trace("In gotomicdataexception"+e);
                    }
                }
    
                private function gotMicData(event:SampleDataEvent):void 
                { 
                    while(event.data.bytesAvailable)
                    {
                        var sample:Number = event.data.readFloat();
                        soundBytes.writeFloat(sample);
                    }
                }
    
                private function playbackData():void
                {
    
                }
    
                protected function this_creationCompleteHandler(event:FlexEvent):void
                {
                    setupMicrophoneList();
                }
    
    
    
            ]]>
        </fx:Script>
        <s:layout>
            <s:VerticalLayout />
        </s:layout>
    
        <mx:ComboBox id="comboMicList" dataProvider="{microphoneList}" />
        <mx:Button id="setupmic" label="Select Mic" click="setupMicrophone()"/>
        <s:HGroup>
            <mx:Button id="startmicrec" label="Start Rec" click="startMicRecording()"/>
            <mx:Button id="stopmicrec" label="Stop Rec" click="stopMicRecording()"/> 
            <!--<mx:Button id="playrecsound" label="Play sound" click="playbackData()"/>-->
        </s:HGroup>
    </s:Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Description My application record sound from phone microphone. I am using android standard classes
I'm trying to record sound by creating an android application. here is the code:
I'm making an application where I will: Record from the microphone and do some
I am making simple AS3 application that will record audio from microphone and after
My application record some sound and use standard player to playback it. I would
I am developing an application in which I want to record the sound of
iam trying to record sound from an activex WMP control playing an internet radio
I don't want sound-to-text software. What I need is the following: I'll record multiple
I writing simple application that need to make some record of the incoming sound.
I have been using the code in http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html to record audio. Basically this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.