From a4ed41915620408e13313d9e523536440e46ac8c Mon Sep 17 00:00:00 2001 From: Gena Batalski Date: Sun, 11 Feb 2018 13:27:45 +0100 Subject: [PATCH] Minor improvements (#5) * folder build shoud be ignored * added hint about gTTS support to get vernie chatter * determines full path to vernie.commands * catches tts exception if an empty text passed to `say` command --- .gitignore | 3 ++- README.md | 4 +++- examples/vernie/__init__.py | 9 +++++++-- examples/vernie/run_commands_file.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index bd88afc..4775f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea *.iml -*.pyc \ No newline at end of file +*.pyc +build \ No newline at end of file diff --git a/README.md b/README.md index e9f7e14..ad10df1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ Demonstrational videos: ## Usage -_Please note that it requires [gattlib](https://bitbucket.org/OscarAcena/pygattlib) to be installed, which is not supported on Windows._ +_Please note:_ +- _it requires [gattlib](https://bitbucket.org/OscarAcena/pygattlib) to be installed, which is not supported on Windows._ +- _to enable the text-to-speech functionality [gTTS](https://github.com/pndurette/gTTS) may be installed but is not required by default._ Install library like this: ```bash diff --git a/examples/vernie/__init__.py b/examples/vernie/__init__.py index b249f24..1a4fbb1 100644 --- a/examples/vernie/__init__.py +++ b/examples/vernie/__init__.py @@ -41,7 +41,8 @@ SPEECH_LANG_MAP = { "commands help": "Available commands are: " "forward, backward, turn left, turn right, " "head left, head right, head straight, shot and say", - "finished": "Thank you! Robot is now turning off" + "finished": "Thank you! Robot is now turning off", + "text is empty": "Please, enter not empty text to say!" }, "ru": { "ready": "Робот Веернии готов к работе", @@ -49,9 +50,10 @@ SPEECH_LANG_MAP = { "ok": "хорошо", "commands help": "Доступные команды это: вперёд, назад, влево, вправо, " "голову влево, голову вправо, голову прямо, выстрел, скажи", - "Finished": "Робот завершает работу. Спасибо!", + "finished": "Робот завершает работу. Спасибо!", "commands from file": "Исполняю команды из файла", "fire": "Выстрел!", + "text is empty": "Пожалуйста, наберите не пустой текст!" } } @@ -132,6 +134,9 @@ class Vernie(MoveHub): confirm(cmd) self.head(STRAIGHT) elif cmd[0] in ("say", "скажи", "сказать"): + if not cmd[1:]: + self.say("text is empty") + return say(' '.join(cmd[1:])) elif cmd[0] in ("fire", "shot", "огонь", "выстрел"): say("fire") diff --git a/examples/vernie/run_commands_file.py b/examples/vernie/run_commands_file.py index 44091f4..add2869 100644 --- a/examples/vernie/run_commands_file.py +++ b/examples/vernie/run_commands_file.py @@ -9,7 +9,7 @@ def confirmation(command): robot.say(command[0]) -with open("vernie.commands") as fhd: +with open(os.path.join(os.path.dirname(__file__), "vernie.commands")) as fhd: for cmd in fhd.readlines(): sys.stdout.write("%s" % cmd) robot.interpret_command(cmd, confirmation)