2

I want to sample a radio station which broadcasts in format *.m3u8 and to produce the histogram of the first n seconds (where the user fixes n).

I had been trying using radiopy but it doesn't work and gnuradio seems useless. How can I produce and show this histogram?

EDIT: Now I use Gstreamer v1.0 so I can play it directly but now I need to live-sample my broadcast. How can I do it using Gst?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Danis Fischer
  • 375
  • 1
  • 7
  • 27
  • Where exactly is your trouble? I know gstreamer is documented poorly but there's lots of tutorials available to help decode a stream (which is the only thing you need to do) – runDOSrun Jan 24 '15 at 11:11
  • Can you give me some links for decoding a stream from gstreamer? – Danis Fischer Jan 24 '15 at 11:16
  • Some basics to link bindings to command line usage: http://www.jejik.com/articles/2007/01/streaming_audio_over_tcp_with_python-gstreamer/ First, try to make it work via command line, then port it to python imo. – runDOSrun Jan 24 '15 at 11:38

1 Answers1

1

gnuradio seems useless

Well, I'd argue that this is what you're looking for, if you're looking for a live spectrogram:

GNU Radio showing waterfall

As you can see, it's but a matter of connecting a properly configured audio source to a Qt GUI sink. If properly configured (I wrote an answer about that, and a GNU Radio wiki page as well).

Point is: you shouldn't be trying to play an internet station by yourself. Let a software do that which knows what it is doing.

In your case, I'd recommend:

  1. using VLC or mplayer to write the radio, after decoding it to PCM 32bit float of a fixed sampling rate to a file.
  2. Use Python with the libraries Numpy to open that file (samples = numpy.fromfile(filename, dtype=numpy.float32)), and matplotlib/pyplot to plot a spectrogram to a file, i.e. something like (untested, because written right here):

#!/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")
Community
  • 1
  • 1
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94