How to encode a record Audio of AS3 in PHP

I am trying to build a way to encode data AS3 audio recording in WAV in PHP. I used a library of WAV in AS3 coders previously, but a record 2 minutes would take 4 to 6 minutes on mobile, depending on the device. So I need to encode to WAV (or any other format that would make usable) in PHP to take the load of the application.

I have transated this encoder of Thibault Imbert to PHP. See the translation:

function encode($samples, $channels = 2, $bits = 16, $rate = 44100){
    $data = create($samples);
    $length = strlen($data);
    $bytes = createHeaders($length, $channels, $bits, $rate);
    $bytes .= $data;
    return $bytes;
}


function create($samples) {
    $newBytes = '';
    $bytes = unpack("f*", $samples);

    foreach ($bytes as $value) {
        $newBytes .= pack("V*",$value * 0x7FFF);
    }
    return $newBytes;
}


function createHeaders($length, $channels = 2, $bits = 16, $rate = 44100) {
    $RIFF = "RIFF";
    $WAVE = "WAVE";
    $FMT = "fmt ";
    $DATA = "data";
    $header  = '';
    $header .= $RIFF;
    $header .= pack("I*", $length + 44);
    $header .= $WAVE;
    $header .= $FMT;
    $header .= pack("I*", 16);
    $header .= pack("v*", 1);
    $header .= pack("v*", $channels);
    $header .= pack("I*", $rate);
    $header .= pack("I*", ( $rate * $channels * ($bits >> 3)));
    $header .= pack("v*", ($channels * ($bits >> 3)));
    $header .= pack("v*", $bits);
    $header .= $DATA;
    $header .= pack("I*", $length);
    return $header;
}

Which will create a file readable by the right length (if the headers are obviously correct), but there is only silence when it is played. If I change the package size in 'create()' to ' f * ' (instead of unsigned 32-bit little endian int, float), I get static and I can faintly hear the sound in the background. I can't solve this multiplier to clear up the static method, however. (EDIT: before it is mentioned, I know the asterisk is not necessary for most, if not all of the package formats.) It was something that I tried to see if she could fix things and I never removed it)

The file itself is created as if:

private function start():void {
          if ( !mic ) {
                    this.mic = Microphone.getMicrophone();
                    this.mic.rate = 44;
                    this.mic.setSilenceLevel( 0, 10000 );
                    this.recording = new ByteArray();
          }
        this.recording.length = 0; //reset byte array in case this is not first recording
          this.mic.addEventListener( SampleDataEvent.SAMPLE_DATA, this.saveSample );
}

private function saveSample( e:SampleDataEvent ):void {
          while( e.data.bytesAvailable ) {
                    var byte:Number = e.data.readFloat();
                    this.recording.writeFloat( byte );
          }
}

public function stopRecording():void {
          var file:File = File.applicationStorageDirectory.resolvePath( "audio-recording.wav" );
          this.fs.open( file, FileMode.WRITE );
          this.fs.writeBytes( this.recording );
          this.fs.close();
}

I'm trying to encode the file is saved in stopRecording(). At this point, I don't know what to do. I tried to translate an other encoder as well, but that seemed to run through the memory as if it was nothing.

Does anyone have any suggestions as to what is the problem? The two encoders work very well in AS3. Is this a problem with the write file? Problem with writing the audio data in the byte array? Any suggestions will be useful

So I was unable to find a way to do this via PHP, but I have figure out how do it in a way that is effective and freaking fast in AS3. I realized that the slow fuse of encoding has been a loop in the byte array, read each individual byte, manipulating and write it to another array of bytes. This is an inefficient process, but necessary if you want to ignore the encoder of the recorder. The key was not abstract and rather to encode on the fly, like recording that happens.

If you record like this:

private function saveSample( e:SampleDataEvent ):void {
          e.data.position = 0;
          while( e.data.bytesAvailable ) {
                    this.recording.writeShort( e.data.readFloat() * (0x7fff) );
          }
}

It's the encoding that Thibault Imbert wrote as you do a necessary task (pulling the data from the stream and saving it to a byte array).

With this, the data is written as it is necessary and sufficient to add the headers to make a WAV file.

this.recording.position = 0;
this.recording = this.writeHeaders( this.recording, 1 );

private function writeHeaders( data:ByteArray, channels:int=2, bits:int=16, rate:int=44100 ):ByteArray {
          data.position = 0;

          var bytes:ByteArray = new ByteArray();
          bytes.length = 0;
          bytes.endian = Endian.LITTLE_ENDIAN;

          bytes.writeUTFBytes( "RIFF" );
          bytes.writeInt( uint( data.length + 44 ) );
          bytes.writeUTFBytes( "WAVE" );
          bytes.writeUTFBytes( "fmt " );
          bytes.writeInt( uint( 16 ) );
          bytes.writeShort( uint( 1 ) );
          bytes.writeShort( channels );
          bytes.writeInt( rate );
          bytes.writeInt( uint( rate * channels * ( bits >> 3 ) ) );
          bytes.writeShort( uint( channels * ( bits >> 3 ) ) );
          bytes.writeShort( bits );
          bytes.writeUTFBytes( "data" );
          bytes.writeInt( data.length );
          bytes.writeBytes( data );
          bytes.position = 0;
          return bytes;
}

And oila. It's a valid WAV file created without delay after the end of the recording (while I was previously known a delay of 3 times the length of the record on my Nexus 4). I know that's not a very popular topic (Google, Adobe, these forums and StackOverflow were pretty useless to try to solve this problem), but I hope that this solution will help someone along the line.

EDIT: afterwards, make sure that the ByteArray you save in has its endian Endian.LITTLE_ENDIAN property immediately after instantiation. WAV files require this format and are unreadable if is not set to one.

Tags: Adobe Animate

Similar Questions

  • How long can I record audio on windows movie maker? __

    I would like to use the audio in movie maker to record a conversation, but I don't know how long it will record

    Record audio with sound recorder,

    (See help in sound recorder) If you want an alternative to the use of Movie Maker.

    Sound Recorder allows you to record a sound and save it as an audio file on your computer. You can record sound from various audio devices, such as a microphone that is plugged into the sound card on your computer. The types of sources of audio input, you can record from depend on the audio devices you have and sources of input on your sound card.

  • Qosmio F10: How to record audio and video and use QosmioPlayer

    I am owner of a Qosmio F10-122 with TV tuner and I really need HELP. I'm Italian.

    The questions are:
    1 QosmioPlayer version 4.0.1 (2005022812) (according to the procedure of the forum) has installed fine but the sensitivity is poor; in any case the question is: is is possible to record videos? Also is it possible to record audio?

    2 input and video output are stupid; I can see Windows and QosmioTV on HDTV via DVI/SCART but I can't input in MCE TV or QosmioPlayer any signal IN Composite; so the question is once again how can record AUDIO from my Home stereo or VCR VHS VIDEO?

    3. I only use VIDEO IN to WATCH is not to save: where is my fault?

    Thanks, Marco

    Hello Marco

    I did some testing and I can tell you about my experience on Qosmio G20.

    1. as far as I know early versions of Qosmioplayer did not have the registration option but now I hope that your preinstalled version has REC option. If so, please be sure that you have about 5 GB of free space for the recorded material.

    It is not important what signal is sent to your Qosmio (TV or VCR VHS-connected) you can find it if you look at the channels. With REC option, you can save what you want. I tested it with my VCR VHS and I recorded some old movies. This material was recorder und great quality was the same as on cassettes. After recording, I started Windows MCE and transferred the material recorded in Windows using Qosmio player utility.

    I have not tried, but I put t think you will be able to record audio using only Qosmioplayer.
    2. you can record movies VHS if you connect your VCR VHS on the Qosmio using the antenna cable. Launch Media center Edition (TV option) and scan channels. In my case, I could watch movies VHS on MCE on channel 31. Using REC option you can save all documents of video cassettes. Later, you can change the recorded material and create own DVDs. It really isn't a problem.

    Your audio Home Audio recording can be a bit more problematic, and if you want it to be on the professional path you will need a device external and of course some professional recording software.
    3. I don't know what to write here. Just try to do what I already descriebed under 1 and 2.

    Good bye

  • I'm trying to get audio only from a video. I went to record audio only: (as shown) and there is no ' audio only ' click. do I have to upgrade the machine to live music, and if so, how?

    I'm trying to get audio only from a video. I went to record audio only: (as shown) and there is no ' audio only ' click. do I have to upgrade the machine to live music, and if so, how?

    If you are looking to get audio only from a YouTube video, all you need to do is read your video and while it's going to copy the link. Then on another tab, open listentoyoutube.com. Just follow the easy directions and paste the link.

    Hope that helps. I found out a month ago and I have 4 CD made from these audio files. There is a lot of fun to find obscure stuff and making CD of songs.

    Jon

  • How can I record audio programs that run through Windows 7 on the sound recorder? Where is the master volume.

    How to record audio programs in windows 7? -in previous versions of windows, I could use the main volume control to select "wave" and that way save audio playing on other programs playing through windows and using windows as a simple sampling devicem - I have a relatek 11 hd audio device/card's directx - in audio devices ControlPanel / / / / material/sound/manage / I see only selection of recording for the microphone or line - how can - record sound through windows 7 - can I buy a cable and put it in the headphone and microphone - I'm trying to address the problem in a way that is now not in windows - I want to play things and recording in a small way - could you provide an answer on how audio intgrates of hardware and software with windows - I can't believe really wanting I could do on the previous windows versions - please help

    Start - All Programs - Accessories - Sound Recorder will launch the utility. You can easily find it by running aid and entering "sound recording."

    Right click the speaker icon in the system tray, select recording devices and set the desired default entry.

  • How to record audio?

    I have a few questions about it.

    #1.  What are the API to record audio?

    #2.  How do I record audio (for example in what format?) and how do I specify the media to record the audio in?

    #3.  Is it possible to record audio while the application is not in the foreground?  Is there something special I need to do?

    #4.  Is it possible to record calls?

    Thank you.

    String url = "file:///SDCard/BlackBerry/Music/myfile.dat"
    FileConnection conn = (FileConnection) Connector.open( url, Connector.WRITE );
    if( !conn.exists() ){ // create the file
     conn.create();
     OutputStream _output = conn.openOutputStream();
    
     // use output stream as it is shown in the sample
     ....
     _rcontrol.setRecordStream(_output);
     .....
    }
    
  • How can I record audio now?

    Before the update my graphics to a (Radeon 4650) hdmi connection I could record audio. After installing the new graphics card, I had a conflict with the graphics card and my sound card.  A very loud snoring through the TV speakers. I use a 42 inch LG tv as a monitor. I get sound on the tv speakers. Because the hdmi connection supports the audio I removed my sound card. Now I can't record audio. How can I record audio now? Need me a sound card to support the recording with a microphone? When I choose the tape recorder, located in the Accessories menu, I get a message that "a recording device is not found.  Thanks a lot for the answers!

    I went a little less than a year with my card its removed from my machine.               I have re-installed the sound card, after I posted the message above. Then, I chose my hdmi graphics card as my default. At this stage no buzzing high strong ground. So far, everything works fine. Thank you for your response.

  • How to record audio on my computer

    If I want to take a dictaphone which was held hand and record audio on my computer, how can I do this windows 7 is what I

    Hi monkey763,

    If you can connect the recorder to the computer, for example by using a USB connection, you can set the recorder of the Word as a recording device using the following steps:

    1. Right click on the speaker icon in the notification bar (lower right part of the screen near system clock)
    2. Select the recording devices
    3. Select the dictaphone
    4. Select set default

    Let us know if that helps.

  • Satellite L500-113 - how to record audio from the Web site?

    I have a L500-113.

    I am the controller program for an Internet radio station and want to record audio streaming from our website. Regardless of the recording software, I can record only since the built in MIC, even if the flow is fortunately playing on my computer. No other recording device is displayed in Device Manager. Surely I can record of built in the card Realtek sound? I installed the latest drivers/Manager Realtek from Toshiba.

    Any help would be appreciated.

    Thank you

    Hi mate

    I think that the laptop supports a Realtek audio chip.
    I have a laptop with the same Realtek audio chip and I can record the audio stream of a Web site.

    I m using a free tool called no. 23 Recorder.
    Google for it and you will find some details!

  • How to get Windows 7 Sound Recorder to record audio from the computer?

    I team with my boss and another customer meetings and we want their registered and we use phone calls from Gmail which means that audio is delivered directly through the internet, and Sound Recorder, I found out but I can't record audio only regular computer unless I Plug one wire in the headphone jack that goes to the mic socket who made the impossible phone call since taking mic is already taken.

    I saw in Windows help can I change the source to be recorded, but it lists only microphones (one built into my laptop is default).

    Is there a way to change the entry from the audio recording of the computer?

    My alternative is to find a cable between the MIC and the sound output in order to hear, speak and record at the same time, which I have never seen elsewhere.

    I also do this all the time.  All what I have to do to set up the computer for that is: -.

    Control Panel, [view by - small icons, if necessary], Sound, recording tab, set Rec. reading * as default device

    [* the name of your topic in the recording tab may be different - you just choose the entry that is not a micro device]

    Sound recorder will then record sounds coming through the computer.

    - - - - - - - - - - - - - - - - - - - - - - -

    If I ever want to record from the microphone, I need to reverse the above setting by:

    Control Panel, [view by - small icons, if necessary], Sound, recording tab, set the internal mic as default device

    Sound recorder will then record sounds coming through the microphone.

  • How to download and record a song on Firefox?

    When I want to download a song, it goes through flash player only, please tell me how to download and record a song on my phone using Firefox.

                              I will be thankful to you.
    

    long press flash and select Save audio

  • Re: How to transfer movie recorded on the decoder?

    My laptop is a Toshiba dv6-1375. I have Cox cable TV with a SA Explorer 8240 DVR provided Cox.

    How can I transfer recorded content from the video recorder DVR HD my laptop? I know how to connect the cable DVR to my standalone DVD burner - using standard cables 'red-white-yellow' and can save to it.

    But I would like to connect the DVR _directly_ cable to my laptop and therefore to transfer the data backed up to it. I guess I could connect the audio cable to the microphone of my laptop, but how can I connect _video_ leave the VCR DVR to my laptop?

    Thank you.

    The f

    Hey,.

    To be honest, I never heard of Toshiba notebook dv6-1375. Such a model is not known to me

    In any case, I think that this transfer is possible only when your computer has a video in the port and most laptop computers have only one video signal.

  • the sound card for the Pavilion Slimline S3300T will allow me to record audio from the internet?

    I have a Pavilion Slimline S3300T. KC833AV prod # #ABA. OS vista Home Premium 32 bit.  The sound card will allow me to record audio directly from the internet?

    The sound card is not big thing to do with it, but there are third party software out there that will allow you to do.

    WaveTap is recommended by LifeHacker.

    Here is an article on their website explaining how to use it:

    WavTap Audio recordings of your computer by pressing a keyboard shortcut

  • Try to record audio only from a small video clip of a digital camera.

    Try to record audio only from a small video clip of a digital camera.

    How to do it on Vista?

    Hi robt1962,

    Thank you for using answers Forum.

    You may be able to use Windows MovieMaker to extract audio from your video file, depending on the format.

    If you use your favorite search engine and look for "extract the audio from video using windows moviemaker" for more details.

    I hope this helps.
    Chris
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • NO sound when recording Audio - problems with Windows 7 Ultimate 64-bit

    I got in trouble for almost a year now with NO sound when recording Audio with Windows 7 Ultimate 64-bit. I just found this forum today. It's really weird how recording with windows and other sound recorder works perfectly since 1998 or so until the upgrade to win 7. Now every time I try to record it shows no found recording device or just fails to record any sound. As you'll see below I have activated What U Hear so I can use the system recording features sounds.

    I use the functions of audio recording and pdf reader because I'm legally blind. It is one of the few tools that I could use with ease on all my systems windows for many years.

    A similar question has started happening with nvidia graphics cards. AND... I was led to believe that it was a problem with Sony wanting more strong piracy measures built into windows. Am I correct to assume that this is what is happening with the sound also today or is there a solution to this frustrating problem?

    I run a dxdiag & posted that, according to me, you asked another user on the forum, the same or similar problem.

    Help solve this problem would be greatly appreciated as this has been a problem for quite a while now.

    ------------------
    Information System
    ------------------
    Time of this report: 07 25, 2012, 19:06:02
    Computer name: RAIDER
    Operating system: Windows 7 Ultimate 64 - bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.120503) - 2030
    Language: English (regional setting: English)
    Manufacturer: Gigabyte Technology Co., Ltd..
    System model: P67A-UD3-B3
    BIOS: Award BIOS v6.00PG Modular
    Processor: Intel Core i5 - 2500K CPU @ 3.30 GHz (4 CPUs), ~3.6GHz
    Memory: RAM 8192MB
    Available OS memory: 8176MB RAM
    Page file: 2861MB used, 13487 MB of available space
    Windows Dir: C:\Windows
    DirectX version: DirectX 11
    DX setup parameters: not found
    DPI setting: Using System DPI
    System DPI setting: 96 DPI (100%)
    DWM DPI Scaling: disabled
    DxDiag Version: 6.01.7601.17514 64 bit Unicode

    ------------
    DxDiag Notes
    ------------
    Display 1 tab: No problems found.
    Sound tab 1: No problems found.
    2 Audio tab: No problems found.
    Input tab: no problems found.

    -------------
    Sound Devices
    -------------
    Description: SPDIF Out (Sound Blaster X - Fi Surround 5.1 Pro)
    Default audio playback: Yes
    Default voice playback: no
    Hardware ID: USB\VID_041E & PID_30DF & REV_0100 & MI_00
    Manufacturer ID: 65535
    Product ID: 65535
    Type: WDM
    Driver name: ksaud.sys
    Driver version: 6.00.0001.0460 (English)
    Driver attributes: Final retail
    WHQL Logo would be: n/a
    Date and size: 2010-07-30 11:35:08, 1588608 bytes
    Other files:
    Driver provider: Creative Technology Ltd.
    HW Accel level: basic
    Cap flags: 0x0
    Min/Max sample rate: 0, 0
    Static/Strm HW Mix beef: 0, 0
    Static/Strm HW 3D steers: 0, 0
    HW memory: 0
    Management of the voice: No.
    Listen/Src/EAX (TM) 2.0: No, no
    Listen/Src/I3DL2 (TM): No, no
    Sensaura (TM) ZoomFX (tm): No.

    Description: Pregnant (Sound Blaster X - Fi Surround 5.1 Pro)
    Default audio playback: No.
    Default voice playback: Yes
    Hardware ID: USB\VID_041E & PID_30DF & REV_0100 & MI_00
    Manufacturer ID: 65535
    Product ID: 65535
    Type: WDM
    Driver name: ksaud.sys
    Driver version: 6.00.0001.0460 (English)
    Driver attributes: Final retail
    WHQL Logo would be: n/a
    Date and size: 2010-07-30 11:35:08, 1588608 bytes
    Other files:
    Driver provider: Creative Technology Ltd.
    HW Accel level: basic
    Cap flags: 0x0
    Min/Max sample rate: 0, 0
    Static/Strm HW Mix beef: 0, 0
    Static/Strm HW 3D steers: 0, 0
    HW memory: 0
    Management of the voice: No.
    Listen/Src/EAX (TM) 2.0: No, no
    Listen/Src/I3DL2 (TM): No, no
    Sensaura (TM) ZoomFX (tm): No.

    ---------------------
    Sound Capture devices
    ---------------------
    Description: What you Hear (Sound Blaster X - Fi Surround 5.1 Pro)
    Capture audio by default: Yes
    Default voice Capture: No.
    Driver name: ksaud.sys
    Driver version: 6.00.0001.0460 (English)
    Driver attributes: Final retail
    Date and size: 2010-07-30 11:35:08, 1588608 bytes
    Cap flags: 0x0
    Format flags: 0x0

    Description: Microphone (Webcam Pro 9000)
    Capture audio by default: No.
    Default voice Capture: No.
    Driver name: USBAUDIO.sys
    Driver version: 6.01.7601.17514 (English)
    Driver attributes: Final retail
    Date and size: 2010-11-21 13:23:47, 109696 bytes
    Cap flags: 0x0
    Format flags: 0x0

    Description: Line-In/Mic-In (Sound Blaster X - Fi Surround 5.1 Pro)
    Capture audio by default: No.
    Default voice Capture: Yes
    Driver name: ksaud.sys
    Driver version: 6.00.0001.0460 (English)
    Driver attributes: Final retail
    Date and size: 2010-07-30 11:35:08, 1588608 bytes
    Cap flags: 0x0
    Format flags: 0x0

    Hello

    In Services, verify that the Windows Audio service is running and set to automatic.

    a. Click Start and type Services and press ENTER.

    (b) ensure that these services are defined accordingly.

    c. right-click the service, and then click Properties.

    According to the DXDiag, there is no default sound capture selected.

    Description: Pregnant (Sound Blaster X - Fi Surround 5.1 Pro)
    Default audio playback: No.
    Default voice playback: Yes

    Description: What you Hear (Sound Blaster X - Fi Surround 5.1 Pro)
    Capture audio by default: Yes
    Default voice Capture: No.

    Description: Microphone (Webcam Pro 9000)
    Capture audio by default: No.
    Default voice Capture: No.

    Description: Line-In/Mic-In (Sound Blaster X - Fi Surround 5.1 Pro)

    Capture audio by default: No.

    Default voice Capture: Yes

Maybe you are looking for