Archive for the ‘Air’ Category
Recording audio to local file from an Air app
If you want to record audio from an Air app and store that recording locally, unfortunately you can’t simply write the sound file to disk (despite the fact Air has sufficient permissions to do that) because Flex/Air won’t encode audio or video using any of the formats you’d want to store (e.g. .mp3, .wav etc.).
Flash Player 6 and above uses the proprietary Nellymoser codec, and Flash Player 10 introduced support for the Speex codec – which is Open Source and free – but even using Speex it is not possible to write the recording to the file system (much to the annoyance of a lot of developers).
Until such a time as Adobe allow it directly, if you want to record an audio or video file there are two options (as far as I know):
1) Stream the recording to a media server (such as Adobe’s Flash Media Server, or an alternative such as Wowza) and then at the server end provide a service that will return the audio back to the client in a more useful format (e.g. mp3). This isn’t something I’ve done, but believe it would be relatively straightforward (though does have the cost associated with providing the media server service, and obviously only works while the Air app is online).
or
2) Use another technology to record the sound (e.g. a Java application), and make that talk back and forth with the Air app, e.g. via sockets. For example, it’s possible to implement a recorder using the Java Sound library, then, on windows, install that java app as a service that starts automatically; the Air app can then send messages to the java recorder by setting up a socket along the lines of:
... _recorderSocket = new XMLSocket(); _recorderSocket.addEventListener(DataEvent.DATA, onIncomingData); _recorderSocket.connect("127.0.0.1", _myPortNumber); ... // Messages sent back from the java app will arrive here private function handleIncomingData(event:DataEvent):void { switch (event.data as String) { ... } }
Note that although it is possible to make Java Sound record in .mp3, there are licensing implications. An alternative is to record to .wav format – which Flex/Air won’t play back, but you can play back via Java, using sockets for control in the same way as recording.
This route I have done, and it seems to work just fine (though there are some complications re making Java Sound record on Vista, but I’ll blog on those separately).
HTH.