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 6720153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:10:42+00:00 2026-05-26T09:10:42+00:00

I am making simple AS3 application that will record audio from microphone and after

  • 0

I am making simple AS3 application that will record audio from microphone and after that play it using ByteArray data.

I made application, it’s recording, but when I try to play it it’s playing 2x faster…

Interesting thing is that it was okay before, and now it’s faster… And even when I run old file, that have code that was 100% working before it’s also faster now…

Here is code:

import flash.media.*;
import flash.events.*;
import flash.utils.ByteArray;

var ch:SoundChannel;
var soundBytes:ByteArray = new ByteArray();
var soundO:ByteArray = new ByteArray();
var sound:Sound= new Sound();


var mic:Microphone = Microphone.getMicrophone();
var recMode:Boolean = false;
var playMode:Boolean = false;

function init()
{
    mic.codec = "Speex";
    mic.setSilenceLevel(0);
    mic.gain = 50;
    mic.rate = 44;
}

function startRecord():void
{
    mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
}
function stopRecord():void
{
    mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
    soundBytes.position = 0;
    soundO.length = 0;
    soundO.writeBytes(soundBytes);
    soundO.position = 0;
    soundBytes.length = 0;
}

function micSampleDataHandler(event:SampleDataEvent):void
{
    while (event.data.bytesAvailable)
    {
        var sample:Number = event.data.readFloat();
        soundBytes.writeFloat(sample);
    }
}

function playSound():void
{
    soundO.position = 0;
    sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
    ch = sound.play();
    ch.addEventListener(Event.SOUND_COMPLETE,onSC);
}
function stopSound():void
{
    sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
    ch.stop();
    ch.removeEventListener(Event.SOUND_COMPLETE,onSC);
}
function onSC(evt:Event):void
{
    stopSound();
    soundO.position = 0;
    playMode = ! true;
    rec_btn.visible = true;
    rec_btn2.visible = false;
    play_btn.visible = true;
    play_btn2.visible = false;
}
function playbackSampleHandler(event:SampleDataEvent):void
{
    for (var i:int = 0; i < 8192; i++)
    {
        if (soundO.bytesAvailable < 4)
        {
            break;
        }
        var sample:Number = soundO.readFloat();
        event.data.writeFloat(sample);
        event.data.writeFloat(sample);


    }
}

rec_btn.buttonMode = rec_btn2.buttonMode = play_btn.buttonMode = play_btn2.buttonMode = true;
function showPlayUI()
{
    play_btn.visible = true;
}
function hidePlayUI()
{
    play_btn2.visible = false;
    rec_btn2.visible = false;
}
rec_btn.addEventListener(MouseEvent.CLICK,onRecord);
rec_btn2.addEventListener(MouseEvent.CLICK,onRecord);
play_btn.addEventListener(MouseEvent.CLICK,onPlay);
play_btn2.addEventListener(MouseEvent.CLICK,onPlay);


function onRecord(evt:MouseEvent=null):void
{
    if (playMode)
    {
        playMode = ! true;
        play_btn2.visible = false;
        play_btn.visible = true;
        stopSound();
    }


    if (! recMode)
    {
        recMode = true;
        rec_btn.visible = false;
        rec_btn2.visible = true;
        play_btn2.visible = false;
        startRecord();
    }
    else
    {
        recMode = ! true;
        rec_btn.visible = true;
        rec_btn2.visible = false;
        play_btn2.visible = false;
        stopRecord();
        showPlayUI();
    }
}
function onPlay(evt:MouseEvent=null):void
{
    if (recMode)
    {
        recMode = false;
        rec_btn.visible = true;
        rec_btn2.visible = false;
        stopRecord();
    }

    if (! playMode)
    {
        playMode = true;
        rec_btn2.visible = false;
        play_btn2.visible = true;
        play_btn.visible = false;
        playSound();
    }
    else
    {
        playMode = ! true;
        rec_btn2.visible = false;
        play_btn2.visible = false;
        play_btn.visible = true;
        stopSound();
    }
}


hidePlayUI();
init();

As you can see encode rate is 44, which is accept rate…

I tested this on Vista and on XP on my PC, and on both it’s faster…

Here is the URL:
Record and Play

  • 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-05-26T09:10:43+00:00Added an answer on May 26, 2026 at 9:10 am

    Problem was in Speex codec, since it’s encoding microphone differently, so when you try to use it’s levels as Float it’s writing it as encoded sound, not as original…

    Double lines are okay, it should be that way…

    ByteArray is not working okay with Speex codec, use default codec instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making simple application that will take hotel name and price of item,
I'm making a simple tool that will get a string of MySQL commands and
I am making a simple select from mySQL using PHP. I am doing something
I´m making a simple website to display information from XML file that is created
I making simple silverlight application. I need to access and use an image from
I'm making a simple snake game in as3. the problem I'm having is that
I am making a simple login form that saves to a database using MYSQL.
I'm making a simple remove link with an onClick event that brings up a
I am making simple one on server side & one on client side application
I'm making simple C# Winform application. There is a Form having a textbox. I

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.