Bladeren bron

Merge pull request #356 from kalliope-project/pico_path

update pico2wav
Monf 7 jaren geleden
bovenliggende
commit
445612d747
4 gewijzigde bestanden met toevoegingen van 28 en 12 verwijderingen
  1. 1 1
      install/files/python_requirements.txt
  2. 6 5
      kalliope/tts/pico2wave/README.md
  3. 20 5
      kalliope/tts/pico2wave/pico2wave.py
  4. 1 1
      setup.py

+ 1 - 1
install/files/python_requirements.txt

@@ -3,7 +3,7 @@ SpeechRecognition>=3.7.1
 markupsafe==0.23
 pyaudio==0.2.11
 pyasn1>=0.1.8
-ansible==2.2.0.0
+ansible==2.3.0.0
 #python2-pythondialog==3.4.0
 jinja2==2.8
 cffi==1.9.1

+ 6 - 5
kalliope/tts/pico2wave/README.md

@@ -2,11 +2,12 @@
 
 This TTS is based on the SVOX picoTTS engine
 
-| Parameters | Required | Default | Choices      | Comment                                         |
-|------------|----------|---------|--------------|-------------------------------------------------|
-| language   | YES      |         | 6 languages  | List of supported languages in the Note section |
-| cache      | No       | TRUE    | True / False | True if you want to use the cache with this TTS |
-| samplerate | No       | None    | int          | Pico2wave creates 16 khz files but not all USB devices support this. Set a value to                                                        convert to a specific samplerate. For Example: 44100|
+| Parameters | Required | Default            | Choices      | Comment                                                                                                                                  |
+|------------|----------|--------------------|--------------|------------------------------------------------------------------------------------------------------------------------------------------|
+| language   | yes      |                    | 6 languages  | List of supported languages in the Note section                                                                                          |
+| cache      | no       | TRUE               | True,  False | True if you want to use the cache with this TTS                                                                                          |
+| samplerate | no       |                    | int          | Pico2wave creates 16 khz files but not all USB devices support this. Set a value to convert to a specific samplerate. For Example: 44100 |
+| path       | no       | /usr/bin/pico2wave |              | Path to the Pico2wave binary. If not set, Kalliope will try to load it from the environment                                              |                                                     convert to a specific samplerate. For Example: 44100|
 
 
 #### Notes :

+ 20 - 5
kalliope/tts/pico2wave/pico2wave.py

@@ -16,6 +16,7 @@ class Pico2wave(TTSModule):
     def __init__(self, **kwargs):
         super(Pico2wave, self).__init__(**kwargs)
         self.samplerate = kwargs.get('samplerate', None)
+        self.path = kwargs.get('path', None)
 
     def say(self, words):
         """
@@ -31,15 +32,19 @@ class Pico2wave(TTSModule):
 
         .. raises:: FailToLoadSoundFile
         """
-
-        pico2wave_exec_path = ["/usr/bin/pico2wave"]
+        if self.path is None:
+            # we try to get the path from the env
+            self.path = self._get_pico_path()
+            # if still None, we set a default value
+            if self.path is None:
+                self.path = "/usr/bin/pico2wave"
 
         # pico2wave needs that the file path ends with .wav
         tmp_path = self.file_path+".wav"
         pico2wave_options = ["-l=%s" % self.language, "-w=%s" % tmp_path]
 
         final_command = list()
-        final_command.extend(pico2wave_exec_path)
+        final_command.extend([self.path])
         final_command.extend(pico2wave_options)
         final_command.append(self.words)
 
@@ -52,8 +57,18 @@ class Pico2wave(TTSModule):
         if self.samplerate is not None:
             tfm = sox.Transformer()
             tfm.rate(samplerate=self.samplerate)
-            tfm.build(str(tmp_path), str(tmp_path)+("tmp_name.wav"))
-            os.rename(str(tmp_path)+("tmp_name.wav"), tmp_path)
+            tfm.build(str(tmp_path), str(tmp_path) + "tmp_name.wav")
+            os.rename(str(tmp_path) + "tmp_name.wav", tmp_path)
         
         # remove the extension .wav
         os.rename(tmp_path, self.file_path)
+
+    @staticmethod
+    def _get_pico_path():
+        prog = "pico2wave"
+        for path in os.environ["PATH"].split(os.pathsep):
+            path = path.strip('"')
+            exe_file = os.path.join(path, prog)
+            if os.path.isfile(exe_file):
+                return exe_file
+        return None

+ 1 - 1
setup.py

@@ -71,7 +71,7 @@ setup(
         'markupsafe>=1.0',
         'pyaudio>=0.2.11',
         'pyasn1>=0.2.3',
-        'ansible>=2.3',
+        'ansible>=2.3,<2.4',
         py2_prefix + 'pythondialog>=3.4.0',
         'jinja2>=2.8,<=2.9.6',
         'cffi>=1.9.1',