I would like to detect silence from an icecast radio stream, i have attempted the following code, however when i silence the stream the rms value stays the same where i would expect a close to zero value: any help
Code:
from urllib import urlopen
import audioop, numpy as np
url = "http://localhost:8382/listen.mp3"
u = urlopen(url)
data = u.read(8192)
while data:
data = u.read(8192)
#rms = audioop.rms(data, 2)
d = np.frombuffer(data, np.int16)
numpy_rms = np.sqrt(sum(d*d)/len(d))
print numpy_rms, audioop.rms(data, 2)
#print rms
print (min(d), max(d)), audioop.minmax(data,2)
alternate to analysing live stream, but not preferred option: i have considered saving a 10 second mp3 files from the stream but not i am not sure how to analyse MP3. se code below
Code:
#! /usr/bin/env python
import argparse
from icerec.stream_writer import StreamWriter
from pprint import pprint
parser = argparse.ArgumentParser(description='Tool that will record a icecast stream.')
parser.add_argument('url', help="Icecast stream URL")
parser.add_argument('length', type=int, help="Length of time to record stream (in seconds)")
parser.add_argument('-d', '--destination', default="./",
help="File destination. Defaults to current directory")
parser.add_argument('-f', '--filename', default="output.mp3", help="File name of saved stream")
args = parser.parse_args()
s = StreamWriter( args.url, args.length, destination=args.destination, filename=args.filename)
s.record()
pprint(s.metadata)