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
How to Tell a Ruby Method to Expect a Specific Parameter Type
Need Help on Reading Emails with "Mail" Gem in Ruby
Activemodel::Validations on Anonymous Class
I Am Getting This Gem Install Error for Kgio Gem When I Do a Bundle Install
Truncate String When It Is Too Long
How to Interact with a Caldav Server from Ruby
Paperclip and Amazon S3 How to Do Paths
How to Convert a Fraction to Float in Ruby
How to Display Image Pointed by Url in Rails
Using a Self-Signed Certificate
Why Slicing The Params Hash Poses a Security Issue on Mass-Assignment
Rails How to Tell If a Sidekiq Worker Is Done with Perform_Async
What Is 'stringify_Keys' in Rails and How to Solve It When This Error Comes
How to Access Sinatra App on Host Machine with Vagrant Forwarded Ports
How to Properly Manage The Rails Tmp Directory
Can't Log into Active Admin. Any Way to Create an Admin User