jasperproject / jasper-client

Client code for Jasper voice computing platform
MIT License
4.53k stars 1.01k forks source link

How to run an operation in Jasper's main loop #417

Open smokinpuppy opened 8 years ago

smokinpuppy commented 8 years ago

Hi, Quick question, I'd like Jasper to take a picture using a webcam every 30 seconds. Where would I put that?

Thanks,

Robert

edouardpoitras commented 8 years ago

This is quite easy to do.

Jasper v1 (latest master branch)

This can't be done with a module alone in Jasper 1. You need to modify the core code, specifically the client/notifier.py file. On line 26, add something like this:

self.notifiers.append(self.NotificationClient(self.webcam_picture, None))

And then at the end of the file, add your webcam_picture function:

def webcam_picture(self, timestamp):
    # imports should be at the top of the file
    import datetime
    from VideoCapture import Device
    cam = Device()
    cam.saveSnapshot('cam_%s.jpg' % datetime.datetime.now())

The default behaviour for notifications is to run every 30 seconds. If you want to change this, modify line 35 to your needs.

Jasper v2 (latest jasper-dev branch)

There hasn't been much focus on Jasper 2's notification capabilities yet. The core devs seem to be focusing on the new plugin system, translation, and bug fixes. It looks like the notification system has been disabled in the jasper-dev branch.

You can still get this working by following the steps for Jasper 1 above, and doing these additional steps:

However, I feel like users should be able to create working notification plugins without needing to modify Jasper core code. I have created a PR to address this in Jasper 2.

Holzhaus commented 8 years ago

Just wondering: whats the use case? Couldn't you just do that with a cron job?

smokinpuppy commented 8 years ago

Hey guys, thanks for the replies. Yeah, I ended up putting it in the notifier file. I also added a module so I can turn it on and off. I'm using it for a "Security Mode" where the picture is analyzed for faces by openCV and if found it checks if the person in the photo is authorized in the office or not. I'm going to add another part that sends an email with a notification of the unauthorized access.

I have another question, how would I get the jasper to mic.say something from within the notifier.py file?

edouardpoitras commented 8 years ago

@Holzhaus yes you could do almost any notification scenario with cron. However, I like the idea of Jasper initializing the conversation (maybe precluded by a dull beep or configurable sound).

Not to mention the countless users who are not very tech savvy. They could achieve notification functionality by simply installing/enabling modules and not having to deal with the command line for cron or coding/configuration at all. That may not be possible yet, but with the work around #174, it could be soon.

I'm planning to build a notification plugin to alert me when I have entered/exited trades in the market. A parent may want to be notified when a certain sound threshold is hit in the baby's bedroom (Jasper powered baby monitor) - here you would need a multi-jasper setup, but it could work in 2.0 with plugins. A jasper plugin could notify you when you've been sitting at the computer for too long and offer suggestions.

I could easily imagine a scenario where people would be using Jasper and it's rich library of plugins simply for it's notification capabilities, because they don't want to setup and maintain a cron-based solution.

If notifications are supported in 2.0, you can expect many plugins coming from me, as well as modification to my existing jasper-configuration plugin to allow the enabling/disabling of notifications on the fly.

@smokinpuppy This would be getting quite hacky in the current state of Jasper 1 and 2. You may have to deal with merge conflicts when updating Jasper if you apply these changes. If you're OK with dealing with the consequences, you'll want to do something like:

Now you should be able to use the self.mic variable to refer to the active mic object.

smokinpuppy commented 8 years ago

Thank you very much for the reply. I got it to work with your steps :) Also, I completely agree about the notifications, they can get Jasper involved in a lot of things in the field of home automation, robotics, and so on.

Thanks again.

ghost commented 8 years ago

Notifications are not working for me. With same setup, but new code pull...

I was trying with the gmail notifier, it works. and says new mail in the log, but never notifies verbally.