| 1 | import subprocess |
| 2 | from plyer.facades import TTS |
| 3 | from plyer.utils import whereis_exe |
| 4 | |
| 5 | |
| 6 | class EspeakTextToSpeech(TTS): |
| 7 | ''' Speaks using the espeak program |
| 8 | ''' |
| 9 | def _speak(self, **kwargs): |
| 10 | subprocess.call(["espeak", kwargs.get('message')]) |
| 11 | |
| 12 | |
| 13 | class FliteTextToSpeech(TTS): |
| 14 | ''' Speaks using the flite program |
| 15 | ''' |
| 16 | def _speak(self, **kwargs): |
| 17 | subprocess.call(["flite", "-t", kwargs.get('message'), "play"]) |
| 18 | |
| 19 | |
| 20 | def instance(): |
| 21 | if whereis_exe('espeak'): |
| 22 | return EspeakTextToSpeech() |
| 23 | elif whereis_exe('flite'): |
| 24 | return FliteTextToSpeech() |
| 25 | return TTS() |