如何在节点js中读取音频流?

How to read audio stream in node js?

我只想从 http://livestream.rfn.ru:8080/kulturafm/mp3_192kbps 读取一些音频流。我的代码是这样的

http = require('http')

options = 
  host: 'livestream.rfn.ru'
  path: ':8080/kulturafm/mp3_192kbps'

callback = (res) ->
  res.on 'data', (chunk) -> console.log String(chunk)
  res.on 'end', -> console.log('No more data in response.')

http.request(options, callback).end()

输出为:

<html><head><title>Wowza Streaming Engine 4 Monthly Edition 4.4.0 build17748</title></head><body>Wowza Streaming Engine 4 Monthly Edition 4.4.0 build17748</body></html>

没有更多数据响应。我不明白如何从 MP3 流中获取数据。

这里的问题是您将端口 (8080) 放在了路径中。这是不正确的。默认情况下,您的 HTTP 客户端连接到端口 80

您不需要以这种方式指定选项对象。只需传递 URL ,它就会为您解析。使用http.get(),它会为你设置合适的动词和.end()

var streamUrl = 'http://livestream.rfn.ru:8080/kulturafm/mp3_192kbps';
http.get(streamUrl, callback);