| Total Complexity | 5 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| 1 | import subprocess |
||
| 8 | class EspeakPrinter(Printer, ClosableObject): |
||
| 9 | def __init__(self): |
||
| 10 | """ |
||
| 11 | Raises EnvironmentError if VoiceOutput is impossible. |
||
| 12 | """ |
||
| 13 | Printer.__init__(self) |
||
| 14 | ClosableObject.__init__(self) |
||
| 15 | # TODO retrieve language from get_locale and select appropriate voice |
||
| 16 | |||
| 17 | try: |
||
| 18 | self.espeak = subprocess.Popen(['espeak'], stdin=subprocess.PIPE) |
||
| 19 | except OSError: # pragma: no cover |
||
| 20 | print("eSpeak doesn't seem to be installed. You cannot use the " |
||
| 21 | "voice output feature without eSpeak. It can be downloaded" |
||
| 22 | " from http://espeak.sourceforge.net/ or installed via " |
||
| 23 | "your usual package repositories.") |
||
| 24 | raise EnvironmentError |
||
| 25 | except: # pragma: no cover |
||
| 26 | print("Failed to execute eSpeak. An unknown error occurred.", |
||
| 27 | Constants.THIS_IS_A_BUG) |
||
| 28 | raise EnvironmentError |
||
| 29 | |||
| 30 | def _close(self): |
||
| 31 | self.espeak.stdin.close() |
||
| 32 | |||
| 33 | def _print(self, output, **kwargs): |
||
| 34 | self.espeak.stdin.write(output.encode()) |
||
| 35 | self.espeak.stdin.flush() |
||
| 36 |