From 8d4e46d5b3d8950db6105b3e83825a81a3e5c8fb Mon Sep 17 00:00:00 2001 From: "Clayton G. Hobbs" Date: Thu, 4 Feb 2016 00:13:29 -0500 Subject: Moved command configuration to options.json It makes sense to put all the configuration in one place, no? --- README.md | 28 ++++++++++------------------ commands.tmp | 7 ------- kaylee.py | 22 ++++++++-------------- options.json.tmp | 4 ++++ 4 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 commands.tmp diff --git a/README.md b/README.md index 840af58..7d59f01 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,19 @@ but adds a lot of features that go beyond the original purpose of Blather. ## Usage -1. Move commands.tmp to ~/.config/kaylee/commands.conf and fill the file with -sentences and commands to run +1. Move options.json.tmp to ~/.config/kaylee/options.json and fill the + "commands" section of the file with sentences to speak and commands to run. 2. Run kaylee.py. This will generate ~/.local/share/kaylee/sentences.corpus -based on sentences in the 'commands' file, then use the [Sphinx Knowledge Base -Tool](http://www.speech.cs.cmu.edu/tools/lmtool.html) to create and save a new -language model and dictionary. + based on sentences in the "commands" section of options.json, then use the + [Sphinx Knowledge Base Tool](http://www.speech.cs.cmu.edu/tools/lmtool.html) + to create and save a new language model and dictionary. * For GTK UI, run kaylee.py -i g * To start a UI in 'continuous' listen mode, use the -c flag * To use a microphone other than the system default, use the -m flag -3. Start talking +3. Start talking! -**Note:** to start Kaylee without needing to enter command line options all the -time, copy options.json.tmp to ~/.config/kaylee/options.json and edit -accordingly. +**Note:** default values for command-line arguments may be specified in the +options.json file. ### Examples @@ -41,15 +40,8 @@ accordingly. * To run Kaylee with no UI and using a USB microphone recognized as device 2: `./kaylee.py -m 2` -* To have Kaylee pass the matched sentence to the executed command: - `./kaylee.py -p` - - **Explanation:** if the commands.conf contains the line: - - good morning world: example_command.sh - - Then three arguments, 'good', 'morning', and 'world', would get passed to - example_command.sh as `example_command.sh good morning world`. +* To have Kaylee pass each word of the matched sentence as a separate argument + to the executed command: `./kaylee.py -p` * To run a command when a valid sentence has been detected: `./kaylee.py --valid-sentence-command=/path/to/command` diff --git a/commands.tmp b/commands.tmp deleted file mode 100644 index 10fa2c5..0000000 --- a/commands.tmp +++ /dev/null @@ -1,7 +0,0 @@ -# commands are pars of the form: -# KEY: VALUE -# KEY is the sentence to listen for -# VALUE is the command to run when the key is spoken - -hello world: echo "hello world" -start a %d minute timer: (echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) & diff --git a/kaylee.py b/kaylee.py index 5f5b611..4317c36 100755 --- a/kaylee.py +++ b/kaylee.py @@ -33,12 +33,13 @@ class Kaylee: # Load configuration self.config = Config() self.options = vars(self.config.options) + self.commands = self.options['commands'] # Create number parser for later use self.number_parser = NumberParser() - # Read the commands - self.read_commands() + # Create the strings file + self.create_strings_file() if self.options['interface']: if self.options['interface'] == "g": @@ -71,19 +72,12 @@ class Kaylee: self.recognizer = Recognizer(self.config) self.recognizer.connect('finished', self.recognizer_finished) - def read_commands(self): - # Read the commands file - file_lines = open(self.config.command_file) + def create_strings_file(self): + # Open the strings file strings = open(self.config.strings_file, "w") - for line in file_lines: - # Trim the white spaces - line = line.strip() - # If the line has length and the first char isn't a hash - if len(line) and line[0] != "#": - # This is a parsible line - (key, value) = line.split(":", 1) - self.commands[key.strip().lower()] = value.strip() - strings.write(key.strip().replace('%d', '') + "\n") + # Add command words to the corpus + for voice_cmd in sorted(self.commands.keys()): + strings.write(voice_cmd.strip().replace('%d', '') + "\n") # Add number words to the corpus for word in self.number_parser.number_words: strings.write(word + "\n") diff --git a/options.json.tmp b/options.json.tmp index a3eba6f..dfde1e5 100644 --- a/options.json.tmp +++ b/options.json.tmp @@ -1,4 +1,8 @@ { + "commands": { + "hello world": "echo \"hello world\"", + "start a %d minute timer": "(echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) &" + }, "continuous": false, "history": null, "microphone": null, -- cgit 1.4.1