Python 为无线电台m3u生成声音直方图

Python 为无线电台m3u生成声音直方图,python,python-2.7,histogram,radio,m3u8,Python,Python 2.7,Histogram,Radio,M3u8,我想对一个以*.m3u8格式广播的电台进行采样,并生成前n秒的直方图(其中用户确定n) 我一直在尝试使用radiopy,但它不起作用,gnuradio似乎也没用。如何生成并显示此直方图 编辑:现在我使用Gstreamer v1.0,因此可以直接播放,但现在我需要对广播进行现场采样。我如何使用商品及服务税 gnuradio似乎没用 好吧,我认为这就是你要找的,如果你要找的是现场光谱图: 如您所见,这只是将正确配置的音频源连接到QtGUI接收器的问题。如果配置正确(我写了一篇关于这个的文章,还有一

我想对一个以*.m3u8格式广播的电台进行采样,并生成前n秒的直方图(其中用户确定n)

我一直在尝试使用radiopy,但它不起作用,gnuradio似乎也没用。如何生成并显示此直方图

编辑:现在我使用Gstreamer v1.0,因此可以直接播放,但现在我需要对广播进行现场采样。我如何使用商品及服务税

gnuradio似乎没用

好吧,我认为这就是你要找的,如果你要找的是现场光谱图:

如您所见,这只是将正确配置的音频源连接到QtGUI接收器的问题。如果配置正确(我写了一篇关于这个的文章,还有一篇)

重点是:你们不应该试图独自扮演一个网络电台。让软件去做那些知道它在做什么的事情

就你而言,我建议:

  • 使用VLC或mplayer写入收音机,解码后将其以固定采样率的32位浮点值写入PCM文件
  • 使用Python和库Numpy打开该文件(
    samples=Numpy.fromfile(filename,dtype=Numpy.float32)
    ),并使用
    matplotlib
    /
    pyplot
    将光谱图绘制到文件,例如(未测试,因为写在这里):

  • 你的麻烦到底在哪里?我知道gstreamer的文档记录得很差,但是有很多教程可以帮助解码流(这是您唯一需要做的事情),您能给我一些链接来解码来自gstreamer的流吗?一些将绑定链接到命令行用法的基础知识:首先,尝试通过命令行使其工作,然后将其移植到python imo。
    
    #!/usr/bin/python2
    import sys
    import os
    import tempfile
    import numpy
    from matplotlib import pyplot
    
    stream = sys.argv[1] ## you can pass the stream URL as argument
    outfile = sys.argv[2] ## second argument: output file; ending determines type!
    num_of_seconds = min(int(sys.argv[3]), 60) # not more than 1min of streaming
    (intermediate_file, inter_fname) = tempfile.mkstemp()
    # pan = number of output channels (1: mix to mono)
    # resample = sampling rate. this must be the same for all files, so that we can actually compare spectrograms
    # format = sample format, here: native floats
    sys.system("mplayer -endpos %d -vo null -af pan=1 -af resample=441000 -af format=floatne -ao pcm:nowaveheader:file=%s" % num_of_seconds % inter_fname)
    samples = numpy.fromfile(inter_fname, dtype=float32)
    
    pyplot.figure((num_of_seconds * 44100, 256), dpi=1)
    ### Attention: this call to specgram expects of you to understand what the Discrete Fourier Transform does.
    ### This uses a Hanning window by default; whether that is appropriate for audio data is questionable. Use all your DSP skillz!
    ### pyplot.specgram has a lot of options, including colormaps, frequency scaling, overlap. Make yourself acquintanced with those!
    pyplot.specgram(samples, NFFT=256, FS=44100)
    pyplot.savefig(outfile, bbox_inches="tight")