我有一个流媒体应用程序,可以流式传输广播电台并按时间切换到另一个频道,然后在设定的时间段后返回原始流。识别实时流音频是否包含每小时发生一次的特定声音然后在设定的时间段内切换的最佳方法是什么。
这个问题的子集是您如何识别来自python-vlc
. 我有一个sample.mp3
,如果说最后 10 秒包含样本包含的内容,我只需要一个真/假。
我知道如何为两个不同的保存 mp3(即使用 FFT)做到这一点,但不知道如何使用来自 python-vlc 的直播。目前我似乎无法访问直播甚至比较波形,因为许多软件包不允许流式音频,只允许录制文件。
到目前为止的包可以在这里找到,尽管有问题的主要功能在这里:
def set_station(self,station):
# Return if already playing selected station
if station == self.playing:
return
if station == "JJ":
self.url = 'http://live-radio01.mediahubaustralia.com/4DJW/mp3/'
elif station == "JJJ":
self.url = 'http://live-radio01.mediahubaustralia.com/4TJW/mp3/'
# Define VLC media
self.media=self.instance.media_new(self.url)
#self.media.add_option("sout=file/ts:sample.mp3")
# Set player media
self.player.set_media(self.media)
# Play the media
self.player.play()
# Set playing station
self.playing = station
def switcher(self):
# Current time and hour
current_time = dt.datetime.now()
current_hour = int(current_time.hour)
# Check if time is between 59th minute and 3rd minute after the hour
mhour = is_now_between_time_periods(dt.time(current_hour,59,50),
dt.time(current_hour,3,30),
current_time.time())
# Is between 6 and 9am create a half hour window
if current_hour >= 6 and current_hour <= 9:
mhalf = is_now_between_time_periods(dt.time(current_hour,30,50),
dt.time(current_hour,33,30),
current_time.time())
mwindow = mhalf or mhour
else:
mwindow = mhour
# //////////////////////////////////////////
# Rather than time based, I'm after a parsing
# of the stream to find a sequence of
# audio similar to e.g. "sample.mp3".
# e.g. if cosine_similarity(sample.mp3",stream) > 0.7:
# //////////////////////////////////////////
# If satisfied then switch to Triple J (JJJ)
if mwindow:
self.set_station("JJJ")
else:
self.set_station("JJ")
一种想法是使用self.media.add_option("sout=file/ts:stream.mp3")
python-vlc 中的模块流式传输到音频文件,然后提前播放延迟解析该文件,但由于它一直在摄取更多数据,因此无法加载到文件流适当地。