使用Ruby录制音频流(在Rails上) [英] Record audio streaming with Ruby (on Rails)

查看:84
本文介绍了使用Ruby录制音频流(在Rails上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要录制一些广播节目,并使其可供以后收听.

I need to record some radio programs and make them available for later listening.

我已经研究了 Shoutcast API ,以获取音频流资源,但是无法知道如何录制音频广播并将其保存在音频文件中.

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.

我正在寻找任何Ruby库,或者甚至一些有关如何入门的信息.

I'm looking for any Ruby libraries, or even some information on how to get started.

推荐答案

您可以将流保存到文件中,例如:

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

这篇关于使用Ruby录制音频流(在Rails上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆