I have a problem with USB mic input. When using my laptops internal microphone the following recorded buffer plays back just fine:
microphone = Microphone.getMicrophone();
microphone.codec = SoundCodec.SPEEX;
microphone.setLoopBack(false);
microphone.rate = 16;
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, processMicData);
private function gotMicData(micData:SampleDataEvent):void {
micBuffer.writeBytes(micData.data);
}
But when I select the USB mic the sound stutters, like it's adding silence between the buffers. By the way, if I use a program like Audacity to record the USB microphone, everything works fine.
I would recommend trying to use the Microphone.setSilenceLevel() method. It allows you to set a level of microphone activity necessary for flash to read the audio input. Then, when no input is recorded, it won't write in silence when no information is received.
For more info:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d0c.html
Related
I am just curious. I am making a very simple game and I want to include the game logic when the user claps (like do the loud sound). Is it possible in libgdx?
There is AudioRecorder interface in libgdx for the same. You can access PCM data from the microphone on a PC or Android phone.
int samples = 44100;
boolean isMono = true;
AudioRecorder recorder = Gdx.audio.newAudioRecorder(samples, isMono);
This will create an AudioRecorder with a sampling rate of 44.1khz, in mono mode. If the recorder couldn't be created, a GdxRuntimeException will be thrown.
Samples can be read as 16-bit signed PCM:
int seconds = 5;
final short[] data = new short[samples * seconds];
recorder.readSamples(data, 0, data.length);
Audio recording is not supported in the JavaScript/WebGL backend.
I have a flash as3 based webcam video recorder that publishes the webcam video stream and to do this i am using the following codes :
var camera:Camera = Camera.getCamera(0);
var arr:Array = Camera.names;
if(camera != null)
{
videoWidth = topBorderContainer.width;
videoHeight = topBorderContainer.height;
camera.setMode(videoWidth, videoHeight, 30, false);
camera.setQuality(0, 100);
if (camera)
{
videoDisplay.videoObject.attachCamera(camera);
}
}
But problem is that if i am connecting a new document camera at run time and running my webcam tool then Camera.names returning the previously connected document camera name instead of returning the new document camera name.
And to get new document webcam name i have to restart my application again.
But i have no knowledge how to get newly connected document camera name at run time so if anybody know how to get the newly connected document camera name at run time please help me to solve.
It is very likely that you will not be able to pull the trick:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"Scanning the hardware for cameras takes time. When the runtime finds at least one camera, the hardware is not scanned again for the lifetime of the player instance. However, if the runtime doesn't find any cameras, it will scan each time getCamera is called. This is helpful if the camera is present but is disabled; if your SWF file provides a Try Again button that calls getCamera, Flash Player can find the camera without the user having to restart the SWF file."
It is possible that Flash Player treats Workers (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html) as separate Flash Player instances and thus a new Worker would be able to access the renewed list of Cameras. You might want to try it.
I have a website working the same as youtube. At this moment I am trying to create a video image captured by WEBCAM.
The video image should be saved on my computer (by FLV format) first and then if the user is satisfied, he or she can upload it on the server
I am trying to use Actionscript3 in Adobe flash CS5 and Flash media server4
1- How can I do that?
2- Is the flash media server needed?
Please pay attention that we would like to allow the user to save video on his/her computer and then be able to uploaded to the server.
Many thanks.
Assuming the computer can take the overhead of doing the encoding on the fly (or has enough memory to buffer the data then can run the data through an encoding process) then the library mentioned in the SO answer here should work:
Encode video from any format to .flv format in AS3
I believe the Flash media server would only really be necessary in this case for broadcast.
Pseudocode example
private var cam:Camera;
public function Whatever()
{
//In constructor
addEventListener(Event.ENTER_FRAME, grabFrame);
cam = Camera.getCamera();
if (cam != null)
{
var vid:Video = new Video(cam.width, cam.height);
vid.attachCamera(cam);
addChild(vid);
}
}
private function grabFrame(event:Event):void
{
var bd:BitmapData = new BitmapData(cam.width, cam.height)
bd.draw(vid);
//now the BitmapData has a frame of the video, at this point you also
//would want to capture the audio then use the FLV class in the library
}
You can also check out using Red5 as an alternative open source video stream recorder.
http://distriqt.com/post/493
Cheers
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?
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.
I am trying to record the sound of my device connected to Line-In via ActionScript 3.
According to adobe docs ( http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Sound_02.html ), The Microphone class lets your application connect to a microphone or other sound input device on the user's system .
But the Microphone class detects only microphones on my sound card ( Microphone.names array ) , not the "other sound input devices". Maybe there is another way to capture sound from Line-In devices?
Thank you!
Flash is built with security in mind, it won't let you access any hardware except predefined classes like Microphone and Camera (and only after user permission!)
You may have better luck with plugging the device into microphone socket or reroute its signal programmatically, if your soundcard software allows it.