worldveil / dejavu

Audio fingerprinting and recognition in Python
MIT License
6.36k stars 1.43k forks source link

Change Source of Raw Input #46

Closed jpramirez closed 9 years ago

jpramirez commented 10 years ago

Hi, i really love your work, i was wondering one thing. If we could read a raw input like you do with pyaudio, but instead from the Microphone we could add network streams, let say for example that we have something like this:

class Player(object):
    def __init__(self, channel):
        self.pipeline = gst.Pipeline("RadioPipe")
        self.player = gst.element_factory_make("playbin", "player")
        pulse = gst.element_factory_make("pulsesink", "pulse")
        fakesink = gst.element_factory_make("fakesink", "fakesink")
    filesink = gst.element_factory_make('filesink','sink')
    filesink.set_property('location','./output') 
        self.player.set_property('uri', channel)
        self.player.set_property("audio-sink", filesink)
        self.player.set_property("video-sink", fakesink)
    self.pipeline.add(self.player)
    def play(self):
        self.pipeline.set_state(gst.STATE_PLAYING)
    def stop(self):
        self.pipeline.set_state(gst.STATE_PAUSED)

In which i can save the output of the stream directly to the hardrive instead of a file. Have any plans for something like this?

worldveil commented 10 years ago

This seems cool. What would be a use case?

If you can talk a little more about a use case and your proposed addition to the dejavu api that wouldn't break backwards compatibility, I'd certainly accept a PR.

jpramirez commented 10 years ago

A typical usage will be a core developer for example that is using pyradio or developing his own detection system, sometimes and in this days, we rarely have a "real radio" connected or even listen to mp3. right? so we base almost anything we do online , radios, tv etc. For that reasong this feature will be cool. The user present a new source, a stream that can be converted with gstreamer, ffmpeg or whatever to raw format mp3 , etc and either create a virtual output device or output to a file (for recording and decoding later). So basically after that we create a new sink in dejavu or read from a stream, the same way that you did with the microphone.

So, at any given time the user put an url, gst or ffmpeg(avconv) reads it and pass it along to dejavu to create the matching. This will not affect the fingerprinting, just the Recogn part.

Sorry if i make it more complicated ( many hours without sleep by now :) )

worldveil commented 10 years ago

OK, that sounds great and I would gladly accept your PR. What would you like the API to look like as an example?

Wessie commented 10 years ago

The API can probably be extended with a fingerprint_stream of sorts, that accepts something with a read method.

The bigger problem is that most of the fingerprinting code currently assumes it has the whole audio track at hands. This might require quite a bit of reworking of the fingerprinting code.

jpramirez commented 10 years ago

Thanks !! Although my initial plan is not fingerprint the streaming music, just recognizing it. So im assuming that is the method read inside recog can loop between T (T being the time we want to listen to) just in the way that microphone is doing it.

I will write a small proposal with source code, at the beggining with a little delay, for example:

connect to Stream, download T seconds , save file , call the recognize function.

worldveil commented 9 years ago

Great. When you get a proposal together, please open a PR.