Record audio streaming with Ruby (on Rails)

て烟熏妆下的殇ゞ 提交于 2019-12-04 21:31:29

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!