Record audio streaming with Ruby (on Rails)

我是研究僧i 提交于 2019-12-06 14:58:04

问题


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

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