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

2024-04-19 07:38:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我将使用互联网流为一个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

这个输出指示我有什么类型的流,如果有的话

^{pr2}$

我现在想检查一下(样品?)确保中有音频数据的流。这是为了避免有一个正确的流,但它会广播的原因或其他什么都没有(记住,这是一个闹钟,因此生产关键数据:))。在

如何检查此类信息?

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


Tags: 数据formathttpurlstreamtypeerrorcontent