Flash: Recording Sound
I created a thing that records sound. The problem is that it wont save what I recorded.It saves as nothing.
Here is the code I used:
import org.bytearray.micrecorder.encoder.WaveEncoder;
import org.bytearray.micrecorder.events.RecordingEvent;
import org.bytearray.micrecorder.MicRecorder;
import flash.net.FileReference;
var volumes:Number = .5;
var wavEncoder:WaveEncoder = new WaveEncoder(volumes);
var recorder:MicRecorder = new MicRecorder(wavEncoder)
var file:FileReference = new FileReference();
var recordSoundBTN:MovieClip = new RecordSound();
addChild(recordSoundBTN)
recordSoundBTN.x = 55.3
recordSoundBTN.y = 344.35
recordSoundBTN.addEventListener(MouseEvent.CLICK, recordSt)
recorder.addEventListener(RecordingEvent.RECORDING, onRecording);
recorder.addEventListener(Event.COMPLETE, onRecordComplete);
function recordSt(Event:MouseEvent):void
recorder.record();
trace('recorded')
recordSoundBTN.removeEventListener(MouseEvent.CLICK, recordSt)
recordSoundBTN.addEventListener(MouseEvent.CLICK, recordSp)
recordSoundBTN.gotoAndStop(2)
function onRecording(Event:RecordingEvent):void
var eventTime:Number = Event.time
timeText.text = eventTime.toString()
trace('1' + ' ' + eventTime)
function recordSp(Event:MouseEvent):void
recorder.stop();
trace('stoped')
recordSoundBTN.removeEventListener(MouseEvent.CLICK, recordSp)
recordSoundBTN.addEventListener(MouseEvent.CLICK, recordSt)
recordSoundBTN.gotoAndStop(1)
function onRecordComplete(event:Event):void
file.save(recorder.output,"FlashSound.wav");
Here is the code for WaveEncoder:
package org.bytearray.micrecorder.encoder
import flash.events.Event;
import flash.utils.ByteArray;
import flash.utils.Endian;
import org.bytearray.micrecorder.IEncoder;
public class WaveEncoder implements IEncoder
private static const RIFF:String = "RIFF";
private static const WAVE:String = "WAVE";
private static const FMT:String = "fmt ";
private static const DATA:String = "data";
private var _bytes:ByteArray = new ByteArray();
private var _buffer:ByteArray = new ByteArray();
private var _volume:Number;
* @param volume
public function WaveEncoder( volume:Number=1 )
_volume = volume;
* @param samples
* @param channels
* @param bits
* @param rate
* @return
public function encode( samples:ByteArray, channels:int=2, bits:int=16, rate:int=44100 ):ByteArray
var data:ByteArray = create( samples );
_bytes.length = 0;
_bytes.endian = Endian.LITTLE_ENDIAN;
_bytes.writeUTFBytes( WaveEncoder.RIFF );
_bytes.writeInt( uint( data.length + 44 ) );
_bytes.writeUTFBytes( WaveEncoder.WAVE );
_bytes.writeUTFBytes( WaveEncoder.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( WaveEncoder.DATA );
_bytes.writeInt( data.length );
_bytes.writeBytes( data );
_bytes.position = 0;
return _bytes;
private function create( bytes:ByteArray ):ByteArray
_buffer.endian = Endian.LITTLE_ENDIAN;
_buffer.length = 0;
bytes.position = 0;
while( bytes.bytesAvailable )
_buffer.writeShort( bytes.readFloat() * (0x7fff * _volume) );
return _buffer;
Here is the code for RecordingEvent:
package org.bytearray.micrecorder.events
import flash.events.Event;
public final class RecordingEvent extends Event
public static const RECORDING:String = "recording";
private var _time:Number;
* @param type
* @param time
public function RecordingEvent(type:String, time:Number)
super(type, false, false);
_time = time;
* @return
public function get time():Number
return _time;
* @param value
public function set time(value:Number):void
_time = value;
* @return
public override function clone(): Event
return new RecordingEvent(type, _time)
Here is the code for MicRecorder
package org.bytearray.micrecorder
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.SampleDataEvent;
import flash.events.StatusEvent;
import flash.media.Microphone;
import flash.utils.ByteArray;
import flash.utils.getTimer;
import org.bytearray.micrecorder.encoder.WaveEncoder;
import org.bytearray.micrecorder.events.RecordingEvent;
* Dispatched during the recording of the audio stream coming from the microphone.
* @eventType org.bytearray.micrecorder.RecordingEvent.RECORDING
* * @example
* This example shows how to listen for such an event :
* <div class="listing">
* <pre>
* recorder.addEventListener ( RecordingEvent.RECORDING, onRecording );
* </pre>
* </div>
[Event(name='recording', type='org.bytearray.micrecorder.RecordingEvent')]
* Dispatched when the creation of the output file is done.
* @eventType flash.events.Event.COMPLETE
* @example
* This example shows how to listen for such an event :
* <div class="listing">
* <pre>
* recorder.addEventListener ( Event.COMPLETE, onRecordComplete );
* </pre>
* </div>
[Event(name='complete', type='flash.events.Event')]
* This tiny helper class allows you to quickly record the audio stream coming from the Microphone and save this as a physical file.
* A WavEncoder is bundled to save the audio stream as a WAV file
* @author Thibault Imbert - bytearray.org
* @version 1.2
public final class MicRecorder extends EventDispatcher
private var _gain:uint;
private var _rate:uint;
private var _silenceLevel:uint;
private var _timeOut:uint;
private var _difference:uint;
private var _microphone:Microphone;
private var _buffer:ByteArray = new ByteArray();
private var _output:ByteArray;
private var _encoder:IEncoder;
private var _completeEvent:Event = new Event ( Event.COMPLETE );
private var _recordingEvent:RecordingEvent = new RecordingEvent( RecordingEvent.RECORDING, 0 );
* @param encoder The audio encoder to use
* @param microphone The microphone device to use
* @param gain The gain
* @param rate Audio rate
* @param silenceLevel The silence level
* @param timeOut The timeout
public function MicRecorder(encoder:IEncoder, microphone:Microphone=null, gain:uint=100, rate:uint=44, silenceLevel:uint=0, timeOut:uint=4000)
_encoder = encoder;
_microphone = microphone;
_gain = gain;
_rate = rate;
_silenceLevel = silenceLevel;
_timeOut = timeOut;
* Starts recording from the default or specified microphone.
* The first time the record() method is called the settings manager may pop-up to request access to the Microphone.
public function record():void
if ( _microphone == null )
_microphone = Microphone.getMicrophone();
_difference = getTimer();
_microphone.setSilenceLevel(_silenceLevel, _timeOut);
_microphone.gain = _gain;
_microphone.rate = _rate;
_buffer.length = 0;
_microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
_microphone.addEventListener(StatusEvent.STATUS, onStatus);
private function onStatus(event:StatusEvent):void
_difference = getTimer();
* Dispatched during the recording.
* @param event
private function onSampleData(event:SampleDataEvent):void
_recordingEvent.time = getTimer() - _difference;
dispatchEvent( _recordingEvent );
while(event.data.bytesAvailable > 0)
_buffer.writeFloat(event.data.readFloat());
* Stop recording the audio stream and automatically starts the packaging of the output file.
public function stop():void
_microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
_buffer.position = 0;
_output = _encoder.encode(_buffer, 1);
dispatchEvent( _completeEvent );
* @return
public function get gain():uint
return _gain;
* @param value
public function set gain(value:uint):void
_gain = value;
* @return
public function get rate():uint
return _rate;
* @param value
public function set rate(value:uint):void
_rate = value;
* @return
public function get silenceLevel():uint
return _silenceLevel;
* @param value
public function set silenceLevel(value:uint):void
_silenceLevel = value;
* @return
public function get microphone():Microphone
return _microphone;
* @param value
public function set microphone(value:Microphone):void
_microphone = value;
* @return
public function get output():ByteArray
return _output;
* @return
public override function toString():String
return "[MicRecorder gain=" + _gain + " rate=" + _rate + " silenceLevel=" + _silenceLevel + " timeOut=" + _timeOut + " microphone:" + _microphone + "]";
I got the AS file from http://www.bytearray.org/?p=1858
Hi Lumenphon,
Thanks for your reply. Can you suggest me some more
information on this.. like, what are needs to achieve this and how
to store them to any server (I assume this needs Flash Comm.
server!). Any online articles/examples also can be very helpful.
Thnks,
ASB
Similar Messages
-
Recording sound without Flash Media Server?
Hello,
I am totally new to Flash Media Server I need to be able to record sound via a Flash app and save it to a server preferably without the use of a Flash Media Server type setup. There is no requirement for live streaming.
Is it possible to record the sound and save in memory then pass the data/file as a query parameter to the server?
I don't even know if I've posted this in the correct place... any help/guidance will be appreciated.
Thanks.Hi,
You can use any publisher to publish like FMLE and publish the streams to the application in applications folder suppose application name is sampleApp then create a folder in applications folder of FMS root directory and then keep the below mains.asc file which does the recording of published streams to the sampleApp application.
//main.asc
application.onConnect=function(clientObj)
return true;
application.onPublish = function(clientObj,streamObj){
trace("in application publish");
streamObj.record("record");
application.onUnpublish = function(clientObj,streamObj){
trace("on unpublish");
streamObj.record(false);
I think this should solve your problem.
Regards,
Amit -
Record sound from microphone with flash player lower than 10
Hello,
Is it possible for me to record sound from a microphone using a lower version of flash player, say Flash Player 9?
Thanks
PMAs I know it's possible with Player 9:
Package
flash.media
Class
public final class Microphone
Inheritance
Microphone EventDispatcher Object
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 9 -
We shortly I wanted to record something on http://www.musipedia.org/microphone.html so it asked me to allow usage of adobe flash player and when I wanted to record sound he didn't do it so i got to settings and checked microphone it was there and it was set on wright one os i tried to clap in front of him but chart didn't move. Next I went to audio setting on windows to check it and there microphone works fine. So my question is what is wrong why flash player won't record sound from mic? tnx in advance for replies.
Message was edited by: Kage19Odd...
I got top the linked page and set up my mic, and pressed "Record"...
I see the "scrubber" moving to indicate that it's indeed picking up the sound from my mic, but on playback, it's dead silent.
I've got a $90 Logitech porfessional headset with stereo noise cancelling mic, so I can say with pretty good assurance it ISN'T hardware on my end. The mic works with Skype, FaceTime, and QuickTime for recording.
At this point I don't really know what to do. -
Can KN3 export flash with sound?
I'm working on a presentation in KN2 and I need to export a .swf file with sound on each slide. I know I can export to Quicktime with sound, but I'm working with another company that only accepts a .swf files.
Is this fixed in KN3? Any suggestions on how to solve this in KN2?
Mac OS X (10.4.4)ok, I just bought KN3. Opened my KN2 file that has narration on each slide. Saved it in KN3. Exported to Flash with sound.
However at the end I got a error box. "The following problems occurred while trying save document. Export Warning- A media file in slide 1 was not exported" This error occurred with all of my slides.
My audio files were recorded in Quicktime 7.0 Pro as "mov". Should the audio files be saved as a different format for Exporting to Flash?
Can "kworley" let me know the audio format that worked? -
Mixing mp3 with recorded sound
I need to mix 2 sound data, one is a mp3 sound byteArray and the other one is a recorded sound byteArray. I use URLLoader to load the mp3 external file into a byteArray. The sound is recorded on a microhpone and stored in another byteArray. I need to save to a file - the mp3 comes first and the recorded sound after. I am using WavWriter to write it out as a wav file.
The mp3 is in 44Khz and 16-bit rate. The recorded sound is in 44Khz and 8-bit.
Is there a way to do this? I have researched for a few days already and tried a few things, but still cannot find the correct way to do this.
Any help is appreciated!
Thanks!read about there three classes:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChanne l.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundTransf orm.html
"All you have to do is load your different sounds (You have examples there on how to do that in the flash docs I've linked), and play the sounds according to your timeline. Each sound can be played on a different channel, and by this you can 'mix' them. Maintain a array of channels and do whatever you want with them at whatever time you need."
had the same question once, that the replay i've got and it answerd my problem. -
Draw an audio waveform from recorded sound
I have problem with draw static waveform from recorded sound. Here is an example of which I wanted to use: http://cookbooks.adobe.com/post_Draw_an_audio_waveform_from_an_MP3_file-16767.html
Here is an excerpt of my code, where the recorded sound, and I play it:
public function startRecording():void
stop.enabled=true;
soundClip = new ByteArray();
microphone = Microphone.getMicrophone();
microphone.rate = 44;
microphone.gain = 100;
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, microphone_sampleDataHandler);
public function stopRecording():void
play.enabled=true;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, microphone_sampleDataHandler);
level.width = microphone.activityLevel * 0;
level.height = microphone.activityLevel * 0;
protected function microphone_sampleDataHandler(event:SampleDataEvent):void
level.width = microphone.activityLevel * 1;
level.height = microphone.activityLevel * 1;
while (event.data.bytesAvailable)
var sample:Number = event.data.readFloat();
soundClip.writeFloat(sample);
public function startPlaying(soundClip:ByteArray):void
this.soundClip = soundClip;
soundClip.position = 0;
sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sound_sampleDataHandler);
channel = sound.play();
protected function sound_sampleDataHandler(event:SampleDataEvent):void
if (!soundClip.bytesAvailable > 0)
return;
for (var i:int = 0; i < 8192; i++)
var sample:Number = 0;
if (soundClip.bytesAvailable > 0)
sample = soundClip.readFloat();
event.data.writeFloat(sample);
event.data.writeFloat(sample);
Is there any other way than to save the recorded sound as mp3 (which will also be complicated), or can I use this example given and work on ByteArray? I tried to redo it a little, I'm sitting on this already a lot of time and unfortunately to no avail. Any ideas? Tips?
I would like to compare the recorded sound with the original. Draw waveform will be the first step. Maybe you also have some tips of how to compare the two sounds?
I would be very grateful for every answer,
LillyMaybe not related to your problem, but your plugins list shows outdated plugin(s) with known security and stability risks.
# Shockwave Flash 10.0 r32
# Next Generation Java Plug-in 1.6.0_17 for Mozilla browsers
Update the [[Java]] and [[Falsh]] plugin to the latest version.
See
http://java.sun.com/javase/downloads/index.jsp#jdk (you need JRE)
http://www.adobe.com/software/flash/about/
See [[No sound in Firefox]] and [[Video or audio does not play]] -
Record sound in a browser and save to server
i need users to be able to record sound from their
microphones into a browser-based app, which then saves the
resulting sound file on the server. can FMS do this? are there any
tutorials or sample files that illustrate this functionality?
better yet, can this be done without FMS? is there a flash /
coldfusion / pre-fab app solution that will work without the need
for FMS?
thanks!Try a Restart.
Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider. Press and hold the Sleep/Wake button until the Apple logo appears.
Resetting your settings
You can also try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your device settings again.... All of the settings in the settings app will have to be re-entered. You won't lose any data, but it takes time to enter all of the settings again.
Resetting your device
Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears. Apple recommends this only if you are unable to restart it.
Or if this doesn't work and nobody else on the blog doesn't have a better idea you can contact Apple.
Here is a link to their contacts with most of the information below.
http://www.apple.com/contact/ -
I tried using the Voice Memos iPhone app and ended up with a red banner on top of the screen that flashes "recording 00.00" but I can't locate what I thought I was recording. can you help me?
jacknilI found an answer to this on another page (I was having the same problem) This worked for me:
Double-click the Home button.
Swipe left or right until you have located the app you wish to close.
Swipe the app up to close it.
more here: https://discussions.apple.com/thread/5596831 -
Recording sound from DVD and CD play
I just bought a Zen V Plus. Could someone please tell me how to record sound from a DVD and/or CD to my MP3? Thank you!
Try this:
1. Connect the Line IN jack on your player to the line output of an external stereo source, such as a CD or MiniDisc player, using the supplied line-in cable.
2. Press the Back/Options .You may need to do this more than once until the main menu appears.
3. Select Extra button to start a line-in encoding.
5. On your external stereo source, start playing the song you want to encode.
6. While encoding, you can press and hold the Back/Options button and select one of the following items:
Pauses the encoding. You can also pause the encoding by pressing the Play/Pause button.
Stops and saves the encoding. You can also stop the encoding by pressing the Record
Split Ends and saves current recording session, and begins a new one.
7. Press the Record button to end the line-in recording. The recorded track is named LINE followed by the date and time of the recordin YYYY-MM-DD HH:MM:SS<. For example, if you record a track on March 5, 2004 at 2:57 pm, the track is named LINE
This information can also be found in your user's guide, it's a .chm file found in your installation cd. -
Can you record sounds and save as a ringtone with the IPhone4?
I'm new to the IPhone. All other phones I' ve used in the past I could save sounds and use them as a ringtone. I just can't seem to figure it out with the I4. Can it be done?
You can record sounds with the Voice Memos app, then sync them to your computer by selecting "Include voice memos" on the Music tab of y0ur iTunes sync settings and syncing your phone. Once synced to your computer they will appear in a Voice Memos playlist that iTunes creates on the left sidebar. Then you have to convert it to a ringtone using iTunes as shown here: Create free ringtones with iTunes 10. After this is done, you can check the ringtone in your iTunes library, then check Sync Tones on the Tones tab of your iTunes sync settings and sync. Custom ringtones will appear in Settings>Sounds>Ringtone at the top of the list.
-
Hi all.. I am developing an applet that records sound and stores it in a WAV file... The applet is signed and loads in the browser well but it does not give the output, i.e. the WAV file in the specified directory.
Can you please have a look at my code and tell me where Im going wrong?
public void init()
b1=new Button("Record");
add(b1);
b1.addActionListener(this);
b2=new Button("Stop");
add(b2);
b2.addActionListener(this);
public void run()
public void start()
try
audioFile = new File(filename);
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,44100.0F, 16, 2, 4, 44100.0F, false);
info = new DataLine.Info(TargetDataLine.class, audioFormat);
targetType = AudioFileFormat.Type.WAVE;
targetDataLine = (TargetDataLine)AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
catch (LineUnavailableException e)
msg="Exception occured"+e;
repaint();
public void actionPerformed(ActionEvent ae)
String cmd=ae.getActionCommand();
if(cmd.equals("Record"))
try{
virtual_line = targetDataLine;
virtual_audioInputStream= new AudioInputStream(virtual_line);
virtual_targetType = targetType;
System.in.read();
virtual_outputFile = audioFile;
virtual_line.start();
AudioSystem.write(virtual_audioInputStream,virtual_targetType,virtual_outputFile);
}catch(Exception e)
msg="Exception here"+e;
msg="Recording..";
if(cmd.equals("Stop"))
virtual_line.stop();
virtual_line.close();
msg="Stopped";
repaint();
public void paint(Graphics g)
g.drawString(msg,8,80);
}how can i will play a .wav file in applet
-
How to use a recorded sound in voice memos as a ringtone.
How to use a recorded sound in voice memos as a ringtone.
You may have better luck dumping those to computer and using an application that includes the ability to scrub.
Try the Mac App Store for choices. -
In my first iPhone 5, the speaker didn't work and people could not hear me on Speaker phone when I used it. When I used the video recording it did not record sound at all only a hissing/static sound, no voice. I wished for a software fix. I did a hard reset, nothing. I did a full restore to factory settings not putting my backup on and the problem persisted.
i have been provided with this info
You can find troubleshooting tips, how-to articles, and moderated
> > discussion forums on our support website:
> >
> > www.apple.com/support
> >
> > iPhone: Basic troubleshooting
> > http://support.apple.com/kb/HT1737
> >
I did every step in the link that i have been provided with (thank you), but I’m
still experiencing the same issue. My experience with Apple has been
excellent and this has been the first time I have experienced something
like this with an Apple product. I hope we can find a quick solution.
In order to get the iPhone 5 as soon as it launched (being a major fan of
Apple products!), I purchased my iPhone 5 from the UK through a friend of
mine who lives there.
My question is: can I have the faulty device replaced within Saudi by one
of the official resellers here (we have 3: STC, Mobily and Zain)? I want to
avoid the disruption, complication and expense of sending it back to the
UK.
Could you advise whether this is possible or not, and if not how should I
go about having the device replaced?
Thank you in advance for your cooperation.Nice try! Take a hike.
-
Does the ipod nano can record sounds?
Does the iPod nano can record sounds connecting "headphones with microphone"?
Hi uptight,
Yes, the iPod Nano does support MP4 files.
You can find more information about the files the iPod supports here: http://www.apple.com/ipodnano/specs.html
You can convert many videos right from iTunes. This article: http://support.apple.com/kb/HT1211 will walk you through the process with sample files.
-Jason
Maybe you are looking for
-
I have a function as below, which is working fine. this function excutes a package to get all the column values for a given aid from procurementaction table and is stored in a variable l_pa i select one of the column like awardnbr and display the val
-
How to update LTDX table for ZReport of T-Code FBL5N
Hi, We have copied report RFITEMAR(T-code FBL5N) to ZRFITEMAR(T-Code ZFBL5N), to meet some of our requirement. Now, It is not showing Layouts in F4 help of screen field "Layout" in ZFBL5N and also we are not able to set default variant for the same.
-
Fixed my SL freezes, hanging, beachball
After migrating from Leopard to Snow Leopard (10.6.2) about a month ago, I experienced a constant issue with hanging applications, sporadic freezes with a variety of applications. I have gone through all the suggestions posted wrt to this issue and f
-
Peggy...Thanks for comment. Sorry I didn't articulate re paragraph indents. Use Pages '08 and have used Pages Newsletter Template "Johnson Family Newsletter" since day one with v '05 for 4-page doc. Layout is .5 and It has two borders. Outside border
-
Getting ORA-12514 errotr while switchover using DGBROKER
Hi , Please see the error log. DGMGRL> switchover to dgtest1dr1; Performing switchover NOW, please wait... Operation requires shutdown of instance "dgtest1" on database "dgtest1" Shutting down instance "dgtest1"... ORA-01109: database not open Databa