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