python 流式编程_Python的Pyaudio - 如何发挥通过HTTP流式文件

I am trying to figure out how to play an mp3 that exists on my server served through HTTP. I tried to figure out pyglet but there were too many issues with AVBin to make that work (something about dividing by zero in the source code). So, I decided to try PyAudio, but I can't figure out how to stream an mp3 source from HTTP with it. All the examples are wav files and I need examples rather than the docs or I'm afraid I'll have to figure out the particulars of how audio works on the lowest level. All the documentation is confusing for those of us that don't know the lingo (sample rate, etc). Can anyone help?

解决方案

What is your source and target server environments? [ windows / linux / mac? ]. Also are your trying to play an audio file or video?

In either case you can use Gstreamer with python. I've windows laptop, so I tried with Gstreamer 1.0.x from here

Online examples are for Gstreamer 0.10 that does not work with newer Gstreamer 1.0. There lots of modifications that are platform specific.

However, on windows Gstreamer comes with gst-launch binary which works off the shelf. [ For Linux there is equivalent binary ]

Setup

Server Side:

On server side, you need to setup HTTP server. Without knowing specifics of your environment I can say that there are various solutions available , including python http server SimpleHTTPServer.

See solution here

Client Side :

Once http server is installed and running, on your laptop, you can simply run

C:\Python27\Lib\site-packages\gnome> .\gst-launch.exe playbin uri = http://www.freesound.org/data/previews/148/1482641337920-lq.mp3

Replace http server address with your server address and port.

You can call gst-launch in your python script and go creative with it.

OutPut:

I've opened audio files from freesound.org successfully. It should open a audio file being served from your http server as well.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值