Category: Linux
Chatbot is done
I finished writing the chatbot that I was working on. It consists of a set of scripts to prepare the data, and another script that listens for incoming messages and responds. You can get the code and an overview of how it works here.
Obviously, I’m not publishing my chat logs. Use your own. It is designed to work with Pidgin’s HTML-like format for chat logs, but it could be modified to work on almost any corpus. I really should clean up things like the string cleaning routines, but it worked for class, and that’s what actually matters.
Python Pidgin Dbus Monitor
This is a script that registers a callback with Pidgin’s Dbus interface, and then sends a message in response whenever anyone sends an IM. I’m using it for a chatbot, but it could easily be extended to do things like switch X10 light controllers on and off, get the state of hardware connected to the target computer, and so forth. Pidgin has to be running and configured to use Dbus, but it does that by default.
''' Created on Nov 18, 2011 Watches pidgin over Dbus and responds to incoming messages. ''' import dbus from dbus.mainloop.glib import DBusGMainLoop import gobject class StupidResponder(): def getResponse(self, message): #This is where you would do something clever to come up with a response return "Insect! I cannot bear your words! They are TOO TINY!" def got_msg_cb(account, sender, message, conversation, flags): purple.PurpleConvImSend(purple.PurpleConvIm(conversation), responder.getResponse(message)) if __name__ == '__main__': #load a response generator responder = StupidResponder() #Connect to pidgin on Dbus main_loop = DBusGMainLoop() session_bus = dbus.SessionBus(mainloop = main_loop) obj = session_bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") #Add the callback session_bus.add_signal_receiver(got_msg_cb, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg") #Listen loop = gobject.MainLoop() loop.run()
Unresolved imports in Eclipse/Pydev
The Pydev plugin for Eclipse (at least on my system, Ubuntu Linux on a PC) has a hard time with imports, reporting them as unresolved when Python can actually find them. I find this particularly bothersome when I do projects with OpenCV and Beautiful Soup, as it can’t find either of them and so can’t do code completion.
This thread has the answer. In case that goes away, what you need to do is this:
Go to Project Properties -> Interpreter -> the “Configure an Interpreter not listed” hyperlink
Uncheck and recheck the box next to the interpreter you are already using (probably the default one), or make some other change that doesn’t really change things.
Hit “Apply” and go for a soda while PyDev reindexes things.
Open some file with the bogus unresolved import and make an edit, then save it. Pydev will recheck the imports and stop whinging about the unresolved ones.
As they say on the Heart of Gold, anything you cannot deal with now is your own problem.
Mixing software for Linux
As part of my portable sound system, I need something to play. I’m not a DJ, so I’m not going to make mixes on the fly, because I’ll just trainwreck and embarrass myself. Instead, I’m going to carefully tweak and fiddle with mixes at home. That does mean I won’t be able to do the proper DJ thing and have a gradual build, respond to the crowd, etc. Admittedly, some DJs don’t do that either, but I digress…
I also don’t own any records, and only a few CDs. All of my music is MP3s, so I’m going to be making the mix out of MP3s. I’m a Linux user. I have been for 8 years or so. My laptop runs Linux, everything in my house runs Linux, so I’m going to do my mixing on Linux.
Audacity is actively developed, already installed on my machine, and certainly capable of mixing multiple tracks and recording to disk. I know this because I’ve used it before to make a mix of bird sounds, vocals, and machines for a prop that some friends wanted. It supports shifting tempo and pitch, editing MP3s, and adding all sorts of filters and effects.
Mixx also appears to be actively developed, but also looks like it is for live performance. I’m not playing live, so it may be a case of having a great tool for a job that I’m not doing. TerminatorX is also explicitly realtime, and so is not really the tool I’m looking for.
BPMDJ has a lot of sophisticated analysis options (because most club DJs care deeply about Harr wavelet analysis), automixing. On top of that, it appears to be under active development, which is more than I can say about a bunch of Linux mixing tools.
DJPlay looks to be about 4 years old, but may be useful. If nothing else, I can use the BPM counter to figure out the BPM of some of my music and use that as a rough guide for what might mix well. The interface looks like it was designed for live performance, but interacting with controls that mimic physical controls by using a mouse is kind of a recipe for UI disaster.
GDAM is even older, having no new news for the last 8 years. It does, however, support recording mixes to disk. It is intended for live performance, which is not what I’m doing.
Once I’ve installed and played with a few of these mixers, I’ll update this entry with my impressions.
Gstreamer and the Logitech Pro 9000
This is a gstreamer pipeline that takes frames from a UVC camera on /dev/video0 and displays them on the screen, while simultaneously saving one frame per second to a file. In other words, it’s a single-command-line surveillance camera.
gst-launch v4l2src device=/dev/video0 ! ffmpegcolorspace ! video/x-raw-rgb,width=640,height=480 ! identity name=artoolkit ! tee name="logger" ! queue ! ximagesink sync=false logger. ! queue ! videorate ! video/x-raw-rgb,framerate=1/1 ! ffmpegcolorspace! pngenc snapshot=false ! multifilesink location="frame%05d.png"
Obviously, the camera can be set up to display in different resolutions, and save to differently named files. The next one expands the length of the section of the filename that changes to 8 digits, enough for one picture every second for 3.16 years. I also reorganized the order of the parameters so that ARToolkit can work with the data stream and do augmented reality stuff to it.
export ARTOOLKIT_CONFIG="v4l2src device=/dev/video0 ! tee name=logger ! queue ! ffmpegcolorspace ! video/x-raw-rgb,width=640,height=480 ! identity name=artoolkit ! fakesink sync=false logger. ! queue ! videorate ! video/x-raw-rgb,framerate=1/1 ! ffmpegcolorspace ! pngenc snapshot=false ! multifilesink location=frame%08d.png"
Logitech Pro 9000 and Artoolkit
I’m doing a little augmented reality work for my day job, using ARToolKit. ARToolKit works, and is documented, which is a combination of features that appears to be unique in open-source augmented reality software.
I configured my build to use GStreamer, and set my ARTOOLKIT_CONFIG environment variable to v4l2src device=/dev/video0 use-fixed-fps=false ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24,width=640,height=480 ! identity name=artoolkit ! fakesink
That gives a good tradeoff between resolution and speed, and works just fine with the simpleLite demo program that comes with ARToolKit.
Conversation Initiation
A friend of mine said that she felt that she started AIM conversations more than other people started them with her. This made me curious about my AIM use at work, and whether I start more than half of my conversations. Fortunately, I keep logs and have useful tools for log analysis. I googled up some sed oneliners and spent a couple of minutes slapping shell scripts together to get this:
ams@temperance:~/.purple/logs$ find ./ -iname *.html | wc -l
365
ams@temperance:~/.purple/logs$ for file in `find ./ -iname *.html`; do sed -n 2p $file | grep ">AIM_handle|>GChat_handle" ; done | wc -l
72
The first command line finds all the files in my log file directory that are .html logs and counts the number of them with wc -l
. This is how many conversations I have had. Before I ran that command, I deleted all the automated messages from AOL about being logged in in two places, which reduced the count by about 200.
The second command line finds all the files where the second line of the file (after the header) includes either my AOL handle or my GChat handle. That would indicate that the first message of the chat was a message from me, rather than anyone else.
These scripts are not great, as the files may have a second line that isn’t the first sentence of the conversation, but a quick look over the output of ams@temperance:~/.purple/logs$ for file in `find ./ -iname *.html`; do sed -n 2p $file ; done
shows no weird second lines.
According to the scripts, then, I start about one fifth of the conversations I have at work. On my home computer, I have 401 log files, and 101 of them are conversations I started, making the ratio closer to one forth. This makes sense, as I am more likely to start talking to people at home than at work.
It would also be interesting to graph which people I start conversations with more, and which ones start conversations with me.
Recent Comments