Search code examples
pythonosc

Random OSC address pyOSC


I'm receiving OSC signals from a kinect, and I'm running a server using pyOSC listening for messages that contain joint coordinates.

The address of the signal that is sent involves an integer of a fixed length that is random, body tracking id; changes for each tracked body.

How do I accommodate for that in the OSC address, the address format is:

/body/{bodyID}/...

The server is responding with errors because it cannot recognise the address of the OSC message because I don't know the bodyID ahead of time

Any help?


Solution

  • You could define a default message handler:

    def handle_message(self, address, tags, contents, source):
        # do some stuff with the "address" parameter.
    
    server = OSC.OSCServer(('localhost',8000))
    server.addMsgHandler('default', handle_message)
    

    The handle_message function should run every time a message is received by the OSCServer and then you can parse the address there.

    This functionality is a bit buried in OSC.py, but I think it works!