Bläddra i källkod

Moved command configuration to options.json

It makes sense to put all the configuration in one place, no?
Clara Hobbs 8 år sedan
förälder
incheckning
8d4e46d5b3
4 ändrade filer med 22 tillägg och 39 borttagningar
  1. 10
    18
      README.md
  2. 0
    7
      commands.tmp
  3. 8
    14
      kaylee.py
  4. 4
    0
      options.json.tmp

+ 10
- 18
README.md Visa fil

18
 
18
 
19
 ## Usage
19
 ## Usage
20
 
20
 
21
-1. Move commands.tmp to ~/.config/kaylee/commands.conf and fill the file with
22
-sentences and commands to run
21
+1. Move options.json.tmp to ~/.config/kaylee/options.json and fill the
22
+   "commands" section of the file with sentences to speak and commands to run.
23
 2. Run kaylee.py.  This will generate ~/.local/share/kaylee/sentences.corpus
23
 2. Run kaylee.py.  This will generate ~/.local/share/kaylee/sentences.corpus
24
-based on sentences in the 'commands' file, then use the [Sphinx Knowledge Base
25
-Tool](http://www.speech.cs.cmu.edu/tools/lmtool.html) to create and save a new
26
-language model and dictionary.
24
+   based on sentences in the "commands" section of options.json, then use the
25
+   [Sphinx Knowledge Base Tool](http://www.speech.cs.cmu.edu/tools/lmtool.html)
26
+   to create and save a new language model and dictionary.
27
     * For GTK UI, run kaylee.py -i g
27
     * For GTK UI, run kaylee.py -i g
28
     * To start a UI in 'continuous' listen mode, use the -c flag
28
     * To start a UI in 'continuous' listen mode, use the -c flag
29
     * To use a microphone other than the system default, use the -m flag
29
     * To use a microphone other than the system default, use the -m flag
30
-3. Start talking
30
+3. Start talking!
31
 
31
 
32
-**Note:** to start Kaylee without needing to enter command line options all the
33
-time, copy options.json.tmp to ~/.config/kaylee/options.json and edit
34
-accordingly.
32
+**Note:** default values for command-line arguments may be specified in the
33
+options.json file.
35
 
34
 
36
 ### Examples
35
 ### Examples
37
 
36
 
41
 * To run Kaylee with no UI and using a USB microphone recognized as device 2:
40
 * To run Kaylee with no UI and using a USB microphone recognized as device 2:
42
   `./kaylee.py -m 2`
41
   `./kaylee.py -m 2`
43
 
42
 
44
-* To have Kaylee pass the matched sentence to the executed command:
45
-  `./kaylee.py -p`
46
-
47
-  **Explanation:** if the commands.conf contains the line:
48
-
49
-        good morning world: example_command.sh
50
-
51
-  Then three arguments, 'good', 'morning', and 'world', would get passed to
52
-  example_command.sh as `example_command.sh good morning world`.
43
+* To have Kaylee pass each word of the matched sentence as a separate argument
44
+  to the executed command: `./kaylee.py -p`
53
 
45
 
54
 * To run a command when a valid sentence has been detected:
46
 * To run a command when a valid sentence has been detected:
55
   `./kaylee.py --valid-sentence-command=/path/to/command`
47
   `./kaylee.py --valid-sentence-command=/path/to/command`

+ 0
- 7
commands.tmp Visa fil

1
-# commands are pars of the form:
2
-#     KEY: VALUE
3
-# KEY is the sentence to listen for
4
-# VALUE is the command to run when the key is spoken
5
-
6
-hello world: echo "hello world"
7
-start a %d minute timer: (echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) &

+ 8
- 14
kaylee.py Visa fil

33
         # Load configuration
33
         # Load configuration
34
         self.config = Config()
34
         self.config = Config()
35
         self.options = vars(self.config.options)
35
         self.options = vars(self.config.options)
36
+        self.commands = self.options['commands']
36
 
37
 
37
         # Create number parser for later use
38
         # Create number parser for later use
38
         self.number_parser = NumberParser()
39
         self.number_parser = NumberParser()
39
 
40
 
40
-        # Read the commands
41
-        self.read_commands()
41
+        # Create the strings file
42
+        self.create_strings_file()
42
 
43
 
43
         if self.options['interface']:
44
         if self.options['interface']:
44
             if self.options['interface'] == "g":
45
             if self.options['interface'] == "g":
71
         self.recognizer = Recognizer(self.config)
72
         self.recognizer = Recognizer(self.config)
72
         self.recognizer.connect('finished', self.recognizer_finished)
73
         self.recognizer.connect('finished', self.recognizer_finished)
73
 
74
 
74
-    def read_commands(self):
75
-        # Read the commands file
76
-        file_lines = open(self.config.command_file)
75
+    def create_strings_file(self):
76
+        # Open the strings file
77
         strings = open(self.config.strings_file, "w")
77
         strings = open(self.config.strings_file, "w")
78
-        for line in file_lines:
79
-            # Trim the white spaces
80
-            line = line.strip()
81
-            # If the line has length and the first char isn't a hash
82
-            if len(line) and line[0] != "#":
83
-                # This is a parsible line
84
-                (key, value) = line.split(":", 1)
85
-                self.commands[key.strip().lower()] = value.strip()
86
-                strings.write(key.strip().replace('%d', '') + "\n")
78
+        # Add command words to the corpus
79
+        for voice_cmd in sorted(self.commands.keys()):
80
+            strings.write(voice_cmd.strip().replace('%d', '') + "\n")
87
         # Add number words to the corpus
81
         # Add number words to the corpus
88
         for word in self.number_parser.number_words:
82
         for word in self.number_parser.number_words:
89
             strings.write(word + "\n")
83
             strings.write(word + "\n")

+ 4
- 0
options.json.tmp Visa fil

1
 {
1
 {
2
+    "commands": {
3
+        "hello world": "echo \"hello world\"",
4
+        "start a %d minute timer": "(echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) &"
5
+    },
2
     "continuous": false,
6
     "continuous": false,
3
     "history": null,
7
     "history": null,
4
     "microphone": null,
8
     "microphone": null,

Laddar…
Avbryt
Spara