Recording Audio Through Rtmp/Rails

Recording Audio through RTMP/Rails

I was able to get this to work

1) Flash Player 10.1 can get the microphone's ByteArray

2) I captured this ByteArray, used Adobe's WavWriter class (from a microphone tutorial they put together) to create a new ByteArray in proper wav format

3) Sent this over to rails through RubyAMF

4) Used something along the lines of

wav_data = rubyamf_params[0][:wav_data]

f = File.new('c:/hello.wav')
f << wav_data.pack('c'*wav_data.length)
f.close

Once I've got this wav data it won't be too far of a stretch to convert it to an mp3, woo

Using PortAudio wrapper in ruby to record sound to .wav

Let's first clarify the terms you were asking about. For this purpose i will try to explain the audio pipeline in a simplified way. When you are generating a sound as in your example, your sound card periodically requests frames (= buffers = blocks) from your code, which you fill with your samples. The sampling rate defines how many samples you provide within a second and thus the speed with which your samples are played back. The frame size (= buffer size = block size) determines how many samples you provide in one request from the sound card. A buffer is typically quite small, because the buffer size directly affects the latency (large buffer => high latency) and large arrays can be slow (especially ruby arrays are slow).

Similar things happen when you are recording sound from your sound card. Your function gets called every now and then, and the samples from the microphone are typically passed in as an argument to the function (or even just a reference to such a buffer). You are then expected to process these samples, e.g. by writing them to disk.

I know that the thought of "doing everything in Ruby" is quite tempting, because it is such a beautiful language. When you are planning on doing audio processing in real time, i would recommend to switch to a compiled language (C, C++, Obj-C, ...) though. These can handle audio much better, because they're much closer to the hardware than Ruby and thus generally faster, which can be quite an issue in audio processing. This is probably also the reason why there are so few Ruby audio libraries around, so maybe Ruby just isn't the right tool for the job.

By the way, i tried out ruby-portaudio, ffi-portaudio as well as ruby-audio and none of them were working properly on my Macbook (tried to generate a sine wave) which sadly shows again, how Ruby is not capable of handling this stuff (yet?).

streaming on iOS through rtmp

here is what i found till now.
very useful obj-c libs, but costs smt.
- http://www.themidnightcoders.com/products/weborb-for-mobile/universal-mobile-connectivity-overview.html
- http://www.aftek.com/afteklab/aftek-iphone-RTMP-library.shtml

Then, i tried to implement librtmp c lib. But it would take long.
-http://rtmpdump.mplayerhq.hu/librtmp.3.html

So, we decided in the end, to communicate over web sockets and stream over http.

programmatically stream audio with NetStream

Well, it looks like this isn't possible. My workaround is to use SoundFlower to route audio file playback (invoked outside of Flash) into a virtual microphone, which Flash then streams to the media server. From Flash's point of view, its just as if you were manually speaking into the mic.



Related Topics



Leave a reply



Submit