4

This isn't another one of those "How can I record audio in the browser?" questions... I know that the HTML5 Stream API is around the corner and Flash can already access the user's microphone and camera. I'm simply wondering, as a Javascript developer with little knowledge of Flash, if anyone has developed a JS library that hooks into Flash's device capabilities for recording but sends the results back to javascript (presumably using ExternalInterface).

In other words... libraries like SoundManager2 utilize a Flash fallback for audio playback, but they don't seem to allow for recording. Has anyone written a JS library that uses an invisible Flash movie to allow audio recording?

Matt Diamond
  • 11,646
  • 5
  • 29
  • 36
  • I started working on something, but have since stalled. Initial work at github.com/stoive/aud.i-o - however it should really implement the `navigator.getUserMedia()` that WHATWG has defined ( http://www.whatwg.org/specs/web-apps/current-work/complete/video-conferencing-and-peer-to-peer-communication.html#dom-navigator-getusermedia ). It's also buggy. – Stoive May 09 '11 at 00:36

2 Answers2

5

This does most of what you're looking for:

https://code.google.com/p/wami-recorder/

It records audio and sends it to a server via an HTTP POST (avoiding the need for a Flash Media Server.) A JavaScript API is available via ExternalInterface.

I'm not sure why you'd want the audio bytes in JavaScript, but it would probably be easy to modify it to do that too.

Ian McGraw
  • 571
  • 6
  • 9
  • Very cool! It would be great if there was a streaming audio solution (this seems to record a discrete chunk of audio and POST it to the server) but this is still a step in the right direction. – Matt Diamond Dec 01 '11 at 21:16
  • Actually, it has a bit of a streaming protocol too... it's a pain, because it appears the only way to do it is via multiple POSTs.There doesn't seem to be a way to continually add to the body of a POST in Flash despite the fact that HTTP 1.1's chunking protocol allows it. Oh well. – Ian McGraw Dec 01 '11 at 22:50
  • I've just started playing with wami-recorder and can confirm that it actually works as advertised. – Zeke Mar 03 '12 at 08:49
0

Unfortunately, you can't really do Flash audio recording in browser only. The Flash audio interfaces are all designed (surprise surprise) to talk to a Flash media server (or Red5): there is no interface to store recorded audio data locally and pass the recorded audio data to Javascript.

Once you have Red5/FMS setup you can control the recording process from Javascript: you can start/stop/playback the audio stream to/from the server. However, for security reasons you have to have a flash movie that is a minimum of 216 x 138 (see http://blog.natebeck.net/2009/01/tip-of-the-day-tricks-of-the-mic-settings-panel/ for a writeup) otherwise the settings manager won't be shown: this prevents people hiding an audio recording flash widget on a page and eavesdropping.

So no, no invisible flash controlled from javascript.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • 3
    This isn't correct since Flash 10.1 - it allows you to access audio data, and do whatever you please with it - see https://github.com/stoive/aud.i-o/blob/master/audiofeed.mxml (especially the SampleDataEvent bit) – Stoive May 09 '11 at 00:56
  • I appear to stand corrected on the local audio part: I was unaware they had added this since I last looked a year ago. The invisible recording part does remain true: at least the initial flash movie must be big enough to show the security/privacy manager. – Femi May 09 '11 at 01:04
  • 1
    Yeah, not sure how loudly Adobe announced the new audio data access feature, not a big follower of Flash myself. You can still shift the flash video out of the viewport once the user has accepted microphone access, which is invisible... sort of. – Stoive May 09 '11 at 04:01
  • Actually, in some browsers, shifting the Flash causes it to reload, resetting mic permissions. It appears you have to use a combination of wmode="transparent" and elem.style.visible="hidden" to get around all the browser quirks: http://code.google.com/p/wami-recorder/wiki/Quirks – Ian McGraw Dec 01 '11 at 23:02