go back to the articles list

How do I record sound using a microphone and then send it to the server?

I find it interesting sometimes that this type of question still comes through. It means two things to me. One is that Adobe lacks easily accessible information and examples on FMS, or I suppose at the very least the information isn't in obvious spots. Two, there are still new people coming to FMS., which is always good of course.


The question: How do I record sound using a microphone and then send it to the server?

The answer:

This isn't so tough, but my concern with the wording of this question is that the user thinks that perhaps it's possible to record the microphone client side and then save it on the server.

If by chance that is the case, then it isn't really possible. The best you can do in that area with just flash is to buffer a lot and then have the flash player "upload" it to the server. But in reality, it's not saving it anywhere in hard memory and is deleted if you close the flash player. The reason you might want to do something like this is if you are concerned that the user's bandwidth is much lower than they may need to stream the audio up to the server. So you buffer it on the client side (usually if it's under 30 seconds of audio you should be ok) and then flush the buffer when it reaches the limit.

So, how about some code then:

I won't cover making a net connection to the server and all that because I've talked about that in the past and there really are lots of examples of it (every FMS app needs to connect to the server..)

Once a connection has been made to the server, let's call a function called getMic()

Assuming the netConnection object is "nc", netstream to publish the mic is "ns" and the microphone object is "mic"

//this function will get the microphone object and set some parameters for it
function getMic(){
//first we need a netstream object to connect the mic to
ns = new NetStream(nc);

//set a small buffer

//we need the microphone object now, get the default mic by passing in nothing in the parantheses
mic = Microphone.get();
//set the quality of the microphone, this can be set to 5, 8, 11, 22, or 44

//attach the microphone object to the netstream

//and publish it to the server by passing in the file name and record command. If you want a live stream, then just pass in "LIVE" instead of "RECORD"
ns.publish("myMicrophone", "RECORD");

and that's it really. There are a few other options for the microphone which can be seen here on the livedocs for FMS.

Posted by: Graeme Bull on Apr 05, 2007

Share This Article

STi Chat for Wowza Media Server with Flex | Foundation Edition v4

STi Chat for Wowza Media Server with Flex | Foundation Edition v4

This is a new and improved basic video/audio/text chat application with the ability to invite other users to a private room. The Foundation Edition is meant to give developers the building blocks they need to learn, as well as an entry level solution for those needing a basic chat system. The source code is in AS3 and MXML with the Flex 4.5 SDK. We will be working on more features for the chat as we go and all are free.

$129 Buy Now