Chmmrbot

From WorldGuard

Jump to: navigation, search

Contents

[edit] Update

As the code to Chmmr is getting a bit clunky, I've decided to start a rewrite that makes use of my plugin library. This means adding functionality will be clean rather than ugly hacks. Hopefully will post an update soon about this. - Bundabrg 27/09/2009

[edit] What is it

Every now and then myself and a group of friends like to play some online games. We normally establish a conference call using Skype and play whatever game is the current favourite.

We noticed the following with Skype: -

  • The conference host gets hammered harder than anyone else. This means that on our miserable Australian Internet speeds the host of the game often has to be different to the host of the skype conference. However once again due to our miserable Australian Internet speed, and somewhat do to some very unstable computer configurations, we don't have many players capable of hosting a game without choppiness.
  • If we are playing and someone is late and wants to join the conference, the conference host has to alt-tab out, reject the call, then invite the person to the conference. Its a bit silly.

I found a skype extension that did the following: -

  • Waited for an incoming call. When one came in, it would automatically answer and create a conference. Note that although you can't do this with Skype itself, you can through its API.

This meant I could have another computer on a decent internet connection that just ran this extenstion. Its whole purpose is just to be a dedicate host that automatically creates conferences from everyone who calls it.

For fun I also installed PamBot Chat bot. This is based on ALICE and uses AIML to simulate an AI chat bot. Its actually quite amazing how it works and it inspired me to do some research on aiml in general.

I decided to write my own bot, fully in python, that primarily did the same function of providing group call conferencing, but also had an aiml module in it to provide AI in chats.

This is a public project. You are more than welcome to use any of the code I've written.

Please let me a note in the Talk:Chmmrbot page so I know what you think and where you are using it. If you have some good patches, I'm also interested.

[edit] Features

  • Auto Call Conference - When someone calls the bot, it will auto answer and establish a conference. Anyone else who calls will be added to this conference.
  • AI Chat Bot - Through the use of AIML it will answer private chats, and even group chats. Group chats its name needs to be at the beginning of the sentence, though it will silently still parse anything else and learn stuff that way.
  • Persistence - Every 20 sentences or each time the bot quits, it saves ALL the predicates it has learned. This way it will always remember someone.
  • Commands - Its built to allow one to add commands to it. I had to lightly edit pyAiml to do so. For example, if you want the bot to change the channel topic, once it matches the AIML for the command, it needs to call a callback function in the main code that actually does the work.
  • Speech - It will now make use of text to speech when possible. If you have festival installed it will use that. Currently I've not found an easy way to run festival under windows so this will not work under windows (Might be an idea to add support for other tts that runs under Windows. Feel like programming?). This feature is a bit hacked in at the moment. Update: I'm trying Cepstral voices at the moment so the chmmrbot code has been hacked to allow them (this breaks festival for the moment). I don't think it will currently run under windows well
    • When calling the Bot, it will greet you. You can also have a custom greeting added to the end of the bots greeting.
    • When finishing a call with the Bot, it will notify the rest of the conference (if any) that you have left
    • When in a call, you or someone else types something in a chat channel that bot is in, it will repeat it in the call if and only if all the call conference members are also in the chat channel. This is good because you may be in a game, and a friend types something in a channel that all your partners are in. The bot will speak their message. Update: I've now set it so use a different voice for a person. You can also change the voice that is used for you. If you don't set a voice, and the bot can work out your gender, it will pick an appropriate voice as well.
    • When in a call, the bot responds to something someone has typed in a chat channel, it will also speak its response in the call, prefixing it with 'I said' if more than two people in the chat channel. It will only speak if and only if all the call conference members are also in the chat channel.
  • Multiple Brains - I quite liked the concept of AIML matching and wanted to extend it, without actually touching the standard. One way was to have the input passed through multiple brains, three in fact. The first brain, called input will take the input and pass it through. Whatever comes out of the other end is passed into the process brain as if the original input was provided. Whatever comes out of the process brain is passed through the output brain, which then passes the output out. The default is to have the input and output brains just pass out what came in, which works just like a normal bot. Update: I've disabled the input and output brains for now. Although it sounded good in theory there were some interesting issues that I didn't feel like breaking PyAiml too much to fix. Perhaps later.
  • Duplicate and Shadow Importer - The bot is provided with nothing in its brains. All the AIML files are stored in an import directory. When running the bot for the first time, one issues a ':import' command, which will cause the software to import in all the AIML, stripping off any duplicates and shadowed entries, and place them in the main AIML brain location. It then stores what the shadowed and duplicate entries were. It means you work with the files in the import directory, and then import them in whenever you feel there has been a change.
  • Predicate Lister - When importing aiml files, all the bot and user predicates are retrieved as well and stored in the import directory. That way you can see what predicates are being used and how many times they are being used. Good for ensuring you have bot predicates set correctly.
  • AIML Debugger - As well as the chmmrbot, there is another file called 'aimlDebug.py'. This file is runnable, and will simply load up the same databases as the chmmrbot without needing to connect to Skype. It allows you to converse directly with the bot through the console, and issue commands like :import and :match.
  • AIML Match - Its difficult to know what AIML rule was triggered when providing input. A special :match command has been implemented which gives back in clean AIML which rules would have been triggered in each of the three brains.
  • Silly Name Checker - If someone tries to give themselves a name that is too long or matches a blacklist, the bot will make some quip and change it you don't know jack style. Just a bit of fun.
  • Security - As Chmmr is becoming more public and as myself and my friends actually use her for a purpose, I needed to add some security. So now you can add a comma seperated list of skype nicks in ai/settings.ini of people who have operator status. Operators are able to execute some privilidged commands (such as recording personal AIML). Also, if an operator is in a call with chmmr, a non-operator is unable to call chmmr (it keeps the riffraf out). Also, if a call conference is in session with chmmr and none of the participants are operators, and an operator calls, chmmr will drop the conference and answer the operator.
  • Friends List - To allow people to call in when an operator is called to chmmr, you can add them to a friends list. Any operator is able to add or remove someone from the friends list.

[edit] Commands

Chmmrbot has some default commands. The following are available when talking to the bot: -

  • Ask it to 'tell you when someone calls you'. It will then notify that chat whenever someone calls and connects to its auto conference. You can ask it to 'stop telling when someone calls you' to shut it up.
  • Ask it to 'change the channel topic to <topic>' will cause it to change the skype chat topic. Yeah I know, pretty useless.
  • Ask it to 'greet me with blah' and it will use that when greeting you when you initiate a call
  • Ask it to 'stop greeting me' and it will stop using a custom greeting with you when you initiate a call.
  • (Experimental) Ask it to 'RECORD AIML' and you can then record a personal AIML file (without the aiml tags themselves). This will be merged in with the rest of the AIML if it is clean. Currently a bit insecure as you can use tags like system. It is stored using the skype username of the person so they can overwrite their own file later.
  • Ask the bot 'what voice can I use'. It will list the available voices
  • Ask the bot 'set my voice to <voicename>'. It will set your voice to that voice so that when you talk in a channel and are currently connected to the bot it uses that voice for you.
  • As an operator, ask the bot 'add skypenick as a friend'. The bot will treat that skype nick as a friend. A friend can join a call conference that already has an op in it.
  • As an operator, ask the bot 'remove skypenick as a friend'. The bot will forget that skype nick as being a friend.


The following are available when typing them in the console window when you run the bot: -

  • Type ':?' at the console to bring up some help
  • Type ':import' at the console to import all the AIML from the import directories. This may take a long time
  • Type ':exit' at the console to shut down the program cleanly. It will save all learned predicates and any settings.
  • Prefix anything with ':match ' at the console, and it will perform a pattern match. It will then return what rule was triggered on that pattern and which file that rule exists in for each brain. It will also display a nicely formatted clean AIML entry describing the match. The THAT and TOPIC can be set by separating them with ':'.
 :match hello
 <topic name="*">
  <category>
   <pattern>*</pattern>
   <that>*</that>
   <template><star/></template>
  </category>
 </topic>
 
 <topic name="*">
  <category>
   <pattern>HELLO</pattern>
   <that>*</that>
   <template>Hi there!</template>
  </category>
 </topic>
 
 <topic name="*">
  <category>
   <pattern>*</pattern>
   <that>*</that>
   <template><star/></template>
  </category>
 </topic>
 
 
 :match I am very very very tired
 <topic name="*">
  <category>
   <pattern>* VERY *</pattern>
   <that>*</that>
   <template><srai><star/> <star index="2"/></srai></template>
  </category>
 </topic>
 
 <topic name="*">
  <category>
   <pattern>I AM VERY *</pattern>
   <that>*</that>
   <template><srai>I am <star/></srai></template>
  </category>
 </topic>
 
 <topic name="*">
  <category>
   <pattern>*</pattern>
   <that>*</that>
   <template><star/></template>
  </category>
 </topic>
  • Otherwise, just type anything at the console to talk to the bot in the 'global' context.

[edit] TODO

Some things I'd like to add (perhaps): -

  • Festival/Festvox - Fix this up. Currently its supported under linux, but is fairly hard coded. I've used a Nitech voice. This should be an option. Also would like to use different voices when transcriping a text chat to call chat depending on if the person is male or female (maybe have a range of voices to choose from)
  • Currently I'm using Cepstral voices instead of festival. This was hard coded in a bit. Need a way to choose what voice backend to use (and indeed to be able to use a few if necessary)
  • Channel Predicates - Currently each person who talks, even in a channel, is assigned their own predicates. This means the bot essentially has a separate chat to each person. Some things, like THAT and TOPIC should be set for the channel the bot is chatting in. It should be more group chat friendly.
  • Sphinx - Use speech recognition. This may be totally impossible. I've unsuccessfully tried sphinx and julius and to be honest I don't know what the hell I'm doing. The main problem is it would be good if the bot could perform speech to text translation, then pass it to the aiml backend, then pass it back as text to speech. However this requires a continuous dictation that is not yet possible under Linux. Perhaps with Dragon Dictate Naturally speaking.
  • Somehow work out how to allow the bot to learn dynamically. PyAIML is great in that you can dynamically learn AIML. I'm sure I could use this somehow, even if its by the bot watching others talk without actually responding. I'm thinking that as well as the tree structure it uses to parse sentences, it needs another tree structure to parse logic...
  • Clean up the 'multiple brains' mess. I thought I was onto something interesting with them, but I've now got to clean up the code again. As I use BZR for managing code changes, it shouldn't be hard to revert sections of the code.

[edit] Prerequisites

  • You will need to ensure you have python installed. I've only tested it so far with Python2.6 and 2.5
  • You will need Skype installed to run chmmrbot.py (otherwise you can run aimlDebug.py without needing Skype). It has been tested to work under Windows as well as Linux.

[edit] How to Use

  • Download and extract somewhere
  • Edit 'ai/settings.ini' - This contains stuff that personalises the bot. Make sure to add your (and friends) to the 'op' list in settings.
  • Execute 'chmmrbot.py' with python (or execute 'aimlDebug.py' if you want a stripped down aiml debugger that doesn't require skype)
  • It will display lots of stuff in the console. When it is ready, you can just type stuff in there and have a chat with the robot.
  • If skype is running (and you are running chmmrbot.py), the bot will link to it. You'll need to allow it at least once from within skype.
  • It will now auto answer calls and respond to chats, once again if you are running chmmrbot.py
  • Type ':exit' in the console to have the bot cleanly save its state and close down
  • Type ':help' for some help in the console
  • If this is the first time you have run it, there is nothing in its brain. All the AIML files are located in the ai/aiml/import directory if you wish to customize them. Issue the command :import in the bot console to trigger it to import all the AIML files into its brain. This may take a while as duplicates and shadowed entries are pulled out and put into debug files.

If you want to edit its AI, just look in 'ai/aiml/import' and edit an existing file or create a new one. Good luck, there is lots of information on how on the web. Remember to :import to get the file into the main database. Use the 'Record AIML' feature if you want to record aiml (as an op) from within a chat.

[edit] Test

My bots skype username is 'lsf.chmmr'. Feel free to send it a message. It should reply. Feel free to invite it to a group message chat (just remember that you need to then prefix all your messages to the bot with 'chmmr', ie 'chmmr hello').

Give it a call if you want to hear the text to speech.

It will also accept call invites.

[edit] Experimentation

I am constantly adding stuff to this bot, so if you do call it, it may not work as I describe above. Stuff that I'm working with at the moment: -

  • Voice Recognition - Currently can detect sentences
  • Better input output handling - Using ports instead of wav files. Skypes handling is horrible as it uses call instead of conversation to store this info
  • Timer - Set up a timer event to trigger during a call. Means I can do stuff periodically, like 'whisper' someones name 1 time in 1000 minutes.
  • Internation characters - Currently the bot handles international characters in your name or your text very badly. I'm trying to stomp out this bug.

[edit] Download

You can download it from my bazaar repository by doing the following: -

 bzr branch http://code.worldguard.com.au/public/bzr/chmmrbot

If you do not wish to install Bazaar, a slightly dated copy can be downloaded directly from: -

 http://code.worldguard.com.au/public/files/chmmrbot.zip
Personal tools