Python 如何检查音频流是否正确?

Python 如何检查音频流是否正确?,python,audio,Python,Audio,我将使用互联网流作为DYI闹钟,并想检查给定流是否正确。我所说的“正确”是指流式数据在那里,如果它真的携带音频 通过一个简单的电话来处理“是否存在”部分: import requests urls = [ 'http://statslive.infomaniak.ch/playlist/energy90s/energy90s-high.mp3/playlist.pls', 'http://stream.chantefrance.com/stream_chante_france.m

我将使用互联网流作为DYI闹钟,并想检查给定流是否正确。我所说的“正确”是指流式数据在那里,如果它真的携带音频

通过一个简单的电话来处理“是否存在”部分:

import requests
urls = [
    'http://statslive.infomaniak.ch/playlist/energy90s/energy90s-high.mp3/playlist.pls',
    'http://stream.chantefrance.com/stream_chante_france.mp3',
    'http://streaming.radio.rtl2.fr/rtl2-1-44-128',
    'http://fakestream.example.com'
    ]

for url in urls:
    try:
        r = requests.get(url, stream=True)
    except Exception as e:
        print('failed to get stream: {e}'.format(e=e))
    else:
        if r.ok:
            content_type = r.headers['content-type']
            print('stream {url} is of type {content_type}'.format(url=url, content_type=content_type))
        else:
            print('error getting the stream: {error}'.format(error=r.text))
    r = None    # I do not know how I should really 'close' the stream
这个输出指示我有什么类型的流(如果有的话)

stream http://statslive.infomaniak.ch/playlist/energy90s/energy90s-high.mp3/playlist.pls is of type audio/x-scpls
stream http://stream.chantefrance.com/stream_chante_france.mp3 is of type audio/mpeg
stream http://streaming.radio.rtl2.fr/rtl2-1-44-128 is of type audio/mpeg
failed to get stream: ('Connection aborted.', gaierror(11001, 'getaddrinfo failed'))
我现在想检查(一个样本?)流,以确保其中有音频数据。这是为了避免有一个正确的流,但它会因为某种原因或其他原因而广播(请记住,这是一个闹钟,因此生产关键数据:)

如何检查此类信息?


我看到有,但似乎是针对成熟的音频文件。

我想最好的办法是检查headers@Andrey:哪些标题?我已经检查了响应头(带有内容类型),如代码I postedfile headers中所示,每个音频文件都有定义良好的头:我同意,但这不是一个文件,而是一个流它仍然必须有适当的头,以检查玩家如何播放它?