6 Replies Latest reply on Dec 8, 2009 12:15 AM by David_F57

    Record and playback voice in Flex

    The Bruder Level 1

      Is that possible to do it from Flex (of course with some kind of server side),

       

      Any suggestions?

        • 1. Re: Record and playback voice in Flex
          David_F57 Level 5

          Hi,

           

          What are you trying to achieve ?, maybe I can help if I have an idea what it is you want to do. For instance with media server you have net audio stream recording.

           

           

          David.

          • 2. Re: Record and playback voice in Flex
            The Bruder Level 1

            Hi David,

             

            I'm need to record from the microphone and be able to play in.

             

            In fact i found something:

            http://coenraets.org/blog/2009/11/voice-notes-record-voice-notes-and-persist-them-in-sqlit e-with-air-2/

             

            I'm trying to figure if i can do in from a web flex client.

            • 3. Re: Record and playback voice in Flex
              David_F57 Level 5

              Hi,

               

              I looked at the example and modified it for flex(i'm all setup with fp 10.1 development). Everything compiled ok the settings showed the mic was active and there was sound but it didn't seem that flex was accepting the data.

               

              Anyway have done a bit of reading and it seems that although the flex app compiles cleanly, it ignores the microphone eventlisteners as these mean't to only work with desktop apps.

               

               

              David.

              • 4. Re: Record and playback voice in Flex
                David_F57 Level 5

                Hi,

                 

                finally got the mic working in the browser, with a little help from one of the FP10.1 prerelease guys, Now its a matter of getting mic settings right to record clear sound.

                 

                <?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/halo" width="772" height="561">

                 

                <fx:Script>

                <![CDATA[

                private var mic:Microphone;

                private var rec:ByteArray;

                private var snd:Sound;

                 

                protected function recBtn_clickHandler(event:MouseEvent):void

                {

                if (event.currentTarget.selected == true)

                {

                event.currentTarget.label = "Stop";

                rec=new ByteArray();

                mic = Microphone.getMicrophone();

                mic.rate=44;

                mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);

                ply_Btn.enabled=false;

                }

                else

                {

                mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);

                event.currentTarget.label = "Record";

                ply_Btn.enabled=true;

                }

                }

                 

                protected function plyBtn_clickHandler(event:MouseEvent):void

                {

                if (event.currentTarget.selected == true)

                {

                event.currentTarget.label = "Stop";

                rec.position = 0;

                snd = new Sound();

                snd.addEventListener(SampleDataEvent.SAMPLE_DATA, playRecorded);

                var channel:SoundChannel;

                channel = snd.play();

                channel.addEventListener(Event.SOUND_COMPLETE, stopPlayback);

                }

                else

                {

                event.currentTarget.label = "Play";

                snd.close();

                 

                }

                }

                 

                private function getMicAudio(e:SampleDataEvent): void

                {

                rec.writeBytes(e.data);

                lbl.text = String(rec.length);

                }

                 

                private function playRecorded(e:SampleDataEvent): void

                {

                if (!rec.bytesAvailable > 0)

                return;

                var length:int = 8192;

                for (var i:int = 0; i < length; i++)

                {

                var sample:Number = 0;

                if (rec.bytesAvailable > 0) sample = rec.readFloat();

                e.data.writeFloat(sample);

                e.data.writeFloat(sample);

                }

                }

                 

                private function stopPlayback(e:Event): void

                {

                ply_Btn.selected=false;

                ply_Btn.label="play";

                }

                 

                ]]>

                </fx:Script>

                <s:ToggleButton id="rec_Btn" x="20" y="25" width="80" label="Record" click="recBtn_clickHandler(event)"/>

                <s:ToggleButton id="ply_Btn" x="20" y="60" width="80" label="Play" click="plyBtn_clickHandler(event)" enabled="false"/>

                <s:Label x="121" y="29" text="0" id="lbl"/>

                </s:Application>

                • 5. Re: Record and playback voice in Flex
                  The Bruder Level 1

                  Hi David,

                   

                  Thanks for the help!

                   

                  I tried your code and still can't hear my record.

                   

                  I see that when i start the record i don't get to the 'getMicAudio' callback

                  at all.

                   

                  Maybe i have a configuration problems or i am working with the wrong SDK?

                   

                  (I am working with sdk 4.0.0.10485, and as for the sound, i am using the

                  windows test recorder and it works).

                   

                  What am i missing?

                  • 6. Re: Record and playback voice in Flex
                    David_F57 Level 5

                    Hi,

                     

                    Firstly I can't get this to work in chrome or safari, although I have flashplayer 10.1 installed they don't recognise it, (chrome works in debug mode but the plugins I have are under pre-release so I can't help you there sorry).

                     

                    It works fine in IE8, but you need to do 2 things I allow the site if its remote and 2 switch your microphone on. (right click on the flashfile and adjust the flashplayer settings).

                     

                    http://ezflex.net/recorder/

                     

                    try this if it doesn't work sign in here and i'll show you it working

                     

                    https://connectnow.acrobat.com/davidf57/testdev

                     

                    David.