2

I am recording from a webcam to AMS in an AS3 project and to get the volume level from the microphone I have to attach the microphone to a NetStream. Later when the user initiates recording the NetStream.time value counts from when the camera was attached and not from when NetStream.publish was called. If they stop the recording and record again, now NetStream.time starts from 0. So far the only way to get round this seems to be call publish and then close on the NetStream as soon as the microphone is attached. The docs for AS2 NetStream mention this fact and suggest to call NetStream.publish(false) which doesn't work in AS3, neither does just calling publish with no args.

ns = new NetStream(nc);
ns.attachCamera(cam);
ns.attachAudio(mic);

Then later

ns.publish(filename,"record");
trace(ns.time);

is the elapsed time between attaching the camera and calling publish for the first time.

The only solution I have so far is

ns = new NetStream(nc);
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish(filename,"record");
ns.close();

the when the user starts the reording

ns.publish(filename,"record");
trace(ns.time);

ns.time is now zero. Am I missing something, is there a better solution?

Andi Freeman
  • 21
  • 1
  • 1
  • Interesting, I've never noticed this. I guess it's because I've always attached mic (and camera) to the `NetStream` and started the recording right away. Is there something about your use case that precludes this? Something about getting the volume level? (I don't understand that part). Not creating the `NetStream` until you're ready to start recording seems like the best path. Another (not so great) idea is to use your own `Timer`. – Sunil D. Feb 13 '13 at 16:27
  • I want to show the volume level from the mic before the recording begins so they can adjust the gain or system input level if it looks low. Microphone.level is 0 till you attach it to the NetStream and the first time you do this NetStream.time starts the count, its a bit weird. – Andi Freeman Feb 13 '13 at 22:58
  • Thanks for explaining. There is another way to get the microphone level (the amount of sound it's detecting). It's escaping me now, but I did it in a "microphone/camera wizard" type of display which let the user choose which cam/mic to use. I was able to visualize the sound it was picking up in a "sound meter" -- which worked w/multiple microphones attached to the system and w/out having to connect them to a NetStream. I'm looking at the API right now, but can't seem to find what I used (and don't have access to that code anymore). – Sunil D. Feb 13 '13 at 23:21
  • Perhaps I did what they show [here](http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Sound_19.html), w/the ActivityEvent -- when that is dispatched you can check the microphone's activityLevel property. – Sunil D. Feb 13 '13 at 23:28

1 Answers1

0

You can use mic.setLoopBack(true), wich will route microphone activity to your speakers. You will now be able to see activityLevel. But then you will probaly want to set a soundTransform on the mic with volume 0, so the mic will be effectivetly muted.

Basically.

mic.setLoopBack(true);

var transform:SoundTransform = new SoundTransfrom(); transform.volume = 0;

mic.soundTransform = transform;

After you stop displaying activity level, make shure you remove the transform.