Parcourir la source

Change sample rate of pico2wave (#293)

* Update README.md

* Update pico2wave.py

* Update README.md

* Create install.yml

* Update pico2wave.py

* Update pico2wave.py

* Delete install.yml

* Update python_requirements.txt

* Update setup.py

* Update README.md

* Update pico2wave.py

* Update pico2wave.py

* Update README.md
Patrick il y a 7 ans
Parent
commit
6ac8fc2de0

+ 1 - 1
install/files/python_requirements.txt

@@ -23,4 +23,4 @@ sounddevice>=0.3.7
 SoundFile>=0.9.0
 pyalsaaudio>=0.8.4
 RPi.GPIO>=0.6.3
-
+sox>=1.3.0

+ 2 - 1
kalliope/tts/pico2wave/README.md

@@ -6,6 +6,7 @@ This TTS is based on the SVOX picoTTS engine
 |------------|----------|---------|--------------|-------------------------------------------------|
 | 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|
 
 
 #### Notes :
@@ -17,4 +18,4 @@ Supported languages :
 - French fr-FR
 - Spanish es-ES
 - German de-DE
-- Italian it-IT
+- Italian it-IT

+ 11 - 1
kalliope/tts/pico2wave/pico2wave.py

@@ -2,6 +2,8 @@ import os
 import subprocess
 
 from kalliope.core.TTS.TTSModule import TTSModule
+import sox
+
 import logging
 import sys
 
@@ -13,6 +15,7 @@ class Pico2wave(TTSModule):
 
     def __init__(self, **kwargs):
         super(Pico2wave, self).__init__(**kwargs)
+        self.samplerate = kwargs.get('samplerate', None)
 
     def say(self, words):
         """
@@ -44,6 +47,13 @@ class Pico2wave(TTSModule):
 
         # generate the file with pico2wav
         subprocess.call(final_command, stderr=sys.stderr)
-
+        
+        # convert samplerate
+        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)
+        
         # remove the extension .wav
         os.rename(tmp_path, self.file_path)

+ 2 - 1
setup.py

@@ -90,7 +90,8 @@ setup(
         'sounddevice>=0.3.7',
         'SoundFile>=0.9.0',
         'pyalsaaudio>=0.8.4',
-        'RPi.GPIO>=0.6.3'
+        'RPi.GPIO>=0.6.3',
+        'sox>=1.3.0'
     ],