问题
I need to record some radio programs and make them available for later listening.
I have looked into the Shoutcast API for getting the audio streams resources, but don't have a clue how to record an audio broadcast and save it in an audio file.
I'm looking for any Ruby libraries, or even some information on how to get started.
回答1:
You can save the stream in a file, for example :
require 'net/http'
require 'uri'
url = URI.parse('http://your.stream.domain.com/')
Net::HTTP.start(url.host, url.port) do |http|
f = open("saved_stream.mp3", "w")
begin
http.request_get('/stream_path.mp3') do |resp|
resp.read_body do |segment|
f.write(segment)
end
end
ensure
f.close()
end
end
来源:https://stackoverflow.com/questions/7496110/record-audio-streaming-with-ruby-on-rails