Browse Source

Merged dev_nico into dev

nico 8 years ago
parent
commit
b92b96dd40
6 changed files with 94 additions and 40 deletions
  1. 5 2
      Docs/automated_install.md
  2. 7 2
      core/MainController.py
  3. 7 1
      core/OrderListener.py
  4. 71 31
      install/install.yml
  5. 3 3
      install/install_jarvis.sh
  6. 1 1
      settings.yml

+ 5 - 2
Docs/automated_install.md

@@ -6,11 +6,14 @@ cd
 git clone https://repo/jarvis.git
 git clone https://repo/jarvis.git
 ```
 ```
 
 
-Run the install script with root privileges
+Run the install script.
 ```
 ```
-sudo ./jarvis/install/install_jarvis.sh
+./jarvis/install/install_jarvis.sh
 ```
 ```
 
 
+>**Note:** The install script must not be ran as root or with sudo. 
+You will be prompted to enter your sudo password during the installation process.
+
 You will be prompted to enter your sudo password during the installation process.
 You will be prompted to enter your sudo password during the installation process.
 
 
 Be sure you can record you voice, run the following command to capture audio from your microphone
 Be sure you can record you voice, run the following command to capture audio from your microphone

+ 7 - 2
core/MainController.py

@@ -13,7 +13,7 @@ class MainController:
         # get global configuration
         # get global configuration
         self.settings = SettingLoader.get_settings()
         self.settings = SettingLoader.get_settings()
 
 
-        # create an order listener object
+        # create an order listener object. This last will the trigger callback before starting
         self.order_listener = OrderListener(self.analyse_order)
         self.order_listener = OrderListener(self.analyse_order)
         # Wait that the jarvis trigger is pronounced by the user
         # Wait that the jarvis trigger is pronounced by the user
         self.trigger_instance = self._get_default_trigger()
         self.trigger_instance = self._get_default_trigger()
@@ -28,8 +28,9 @@ class MainController:
         """
         """
         # pause the snowboy process
         # pause the snowboy process
         self.trigger_instance.pause()
         self.trigger_instance.pause()
+        # start listening for an order
+        self.order_listener.start()
         Say(message=self.settings.random_wake_up_answers)
         Say(message=self.settings.random_wake_up_answers)
-        self.order_listener.load_stt_plugin()
 
 
     def analyse_order(self, order):
     def analyse_order(self, order):
         """
         """
@@ -41,6 +42,10 @@ class MainController:
         # restart the trigger when the order analyser has finish his job
         # restart the trigger when the order analyser has finish his job
         Utils.print_info("Waiting for trigger detection")
         Utils.print_info("Waiting for trigger detection")
         self.trigger_instance.unpause()
         self.trigger_instance.unpause()
+        # create a new order listener that will wait for start
+        self.order_listener = OrderListener(self.analyse_order)
+        # restart the trigger to catch the hotword
+        self.trigger_instance.start()
 
 
     def _get_default_trigger(self):
     def _get_default_trigger(self):
         """
         """

+ 7 - 1
core/OrderListener.py

@@ -1,5 +1,7 @@
 import logging
 import logging
 import os
 import os
+from threading import Thread
+
 from cffi import FFI as _FFI
 from cffi import FFI as _FFI
 
 
 from core.Utils import Utils
 from core.Utils import Utils
@@ -9,7 +11,7 @@ logging.basicConfig()
 logger = logging.getLogger("jarvis")
 logger = logging.getLogger("jarvis")
 
 
 
 
-class OrderListener:
+class OrderListener(Thread):
 
 
     def __init__(self, callback=None, stt=None):
     def __init__(self, callback=None, stt=None):
         """
         """
@@ -22,12 +24,16 @@ class OrderListener:
         """
         """
         # this is a trick to ignore ALSA output error
         # this is a trick to ignore ALSA output error
         # see http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time
         # see http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time
+        super(OrderListener, self).__init__()
         self.stt = stt
         self.stt = stt
         self._ignore_stderr()
         self._ignore_stderr()
         self.stt_module_name = stt
         self.stt_module_name = stt
         self.callback = callback
         self.callback = callback
         self.settings = SettingLoader.get_settings()
         self.settings = SettingLoader.get_settings()
 
 
+    def run(self):
+        self.load_stt_plugin()
+
     def load_stt_plugin(self):
     def load_stt_plugin(self):
         if self.stt is None:
         if self.stt is None:
             self.stt_module_name = self.settings.default_stt_name
             self.stt_module_name = self.settings.default_stt_name

+ 71 - 31
install/install.yml

@@ -2,36 +2,76 @@
 - hosts: localhost
 - hosts: localhost
   gather_facts: no
   gather_facts: no
   connection: local
   connection: local
-  become: True
+  vars:
+    - git_url: "git@gitlab.pwit.fr:millionsfortomorrow/jarvis.git"
+    - temp_local_repo: "/tmp/jarvis_repo"
+
+  tasks:
+    - name: clone project in /tmp as standart user
+      git:
+        repo: "{{ git_url }}"
+        dest: /tmp/jarvis_repo
+        accept_hostkey: yes
+
 
 
+- hosts: localhost
+  gather_facts: no
+  connection: local
+  become: True
+  vars:
+    - git_url: "git@gitlab.pwit.fr:millionsfortomorrow/jarvis.git"
+    - temp_local_repo: "/tmp/jarvis_repo"
+    - jarvis_install_path: "/usr/lib/jarvis"
   tasks:
   tasks:
-  - name: Install packages
-    apt: name={{ item }} update_cache=yes
-    with_items:
-      - python-pip
-      - python-dev
-      - libsmpeg0
-      - libttspico-utils
-      - libsmpeg0
-      - flac
-      - dialog
-      - libffi-dev
-      - portaudio19-dev
-      - build-essential
-      - libssl-dev
-      - libffi-dev
-      - sox
-#
-  - name: Copy requirement
-    copy:
-      src: python_requirements.txt
-      dest: /tmp/requirements.txt
-
-  - name: Upgrade pip
-    pip:
-      name: pip
-      state: latest
-
-  - name: Install python libs
-    pip:
-      requirements=/tmp/requirements.txt
+    - name: Install packages
+      apt: name={{ item }} update_cache=yes
+      with_items:
+        - python-pip
+        - python-dev
+        - libsmpeg0
+        - libttspico-utils
+        - libsmpeg0
+        - flac
+        - dialog
+        - libffi-dev
+        - portaudio19-dev
+        - build-essential
+        - libssl-dev
+        - libffi-dev
+        - sox
+
+    - name: Copy requirement
+      copy:
+        src: python_requirements.txt
+        dest: /tmp/requirements.txt
+
+    - name: Upgrade pip
+      pip:
+        name: pip
+        state: latest
+
+    - name: Install python libs
+      pip:
+        requirements=/tmp/requirements.txt
+
+    - name: Check that the repo has been cloned
+      stat:
+        path: "{{ temp_local_repo }}"
+      register: git_repo_stat
+
+    - name: Remove old version if exist
+      file:
+        path: "{{ jarvis_install_path }}"
+        state: absent
+
+    - name: Move repo in /usr/lib
+      command: mv "{{ temp_local_repo }}" "{{ jarvis_install_path }}"
+      when: git_repo_stat.stat.exists
+
+    - name: Add entry in /usr/bin
+      file:
+        src: "{{ jarvis_install_path }}/jarvis.py"
+        dest: /usr/bin/jarvis
+        state: link
+        force: True
+

+ 3 - 3
install/install_jarvis.sh

@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
 # install packages
 # install packages
-apt-get install python-pip
+sudo apt-get install python-pip
 
 
 # install ansible
 # install ansible
-pip install ansible==2.1.1.0
+sudo pip install ansible==2.1.1.0
 
 
 # Install the project
 # Install the project
 cd jarvis/install
 cd jarvis/install
-ansible-playbook install/install.yml -K
+ansible-playbook install.yml -K

+ 1 - 1
settings.yml

@@ -47,7 +47,7 @@ speech_to_text:
 # - voxygen
 # - voxygen
 text_to_speech:
 text_to_speech:
   - pico2wave:
   - pico2wave:
-      language: "en-US"
+      language: "fr-FR"
       cache: True
       cache: True
   - voxygen:
   - voxygen:
       language: "fr"
       language: "fr"