|
31 | 31 | import os |
32 | 32 | import re |
33 | 33 | import shlex |
34 | | -from subprocess import check_output, Popen |
| 34 | +from subprocess import check_output, Popen, PIPE |
35 | 35 |
|
36 | 36 |
|
37 | 37 | def _make_scales(notes): |
@@ -294,20 +294,22 @@ def speak(self, text, espeak_opts='-a 200 -s 130', volume=100, play_type=PLAY_WA |
294 | 294 | self.set_volume(volume) |
295 | 295 |
|
296 | 296 | with open(os.devnull, 'w') as n: |
297 | | - cmd_line = '/usr/bin/espeak --stdout {0} "{1}" | /usr/bin/aplay -q'.format( |
298 | | - espeak_opts, text |
299 | | - ) |
| 297 | + cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)] |
| 298 | + aplay_cmd_line = shlex.split('/usr/bin/aplay -q') |
300 | 299 |
|
301 | 300 | if play_type == Sound.PLAY_WAIT_FOR_COMPLETE: |
302 | | - play = Popen(cmd_line, stdout=n, shell=True) |
| 301 | + espeak = Popen(cmd_line, stdout=PIPE) |
| 302 | + play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n) |
303 | 303 | play.wait() |
304 | 304 |
|
305 | 305 | elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE: |
306 | | - return Popen(cmd_line, stdout=n, shell=True) |
| 306 | + espeak = Popen(cmd_line, stdout=PIPE) |
| 307 | + return Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n) |
307 | 308 |
|
308 | 309 | elif play_type == Sound.PLAY_LOOP: |
309 | 310 | while True: |
310 | | - play = Popen(cmd_line, stdout=n, shell=True) |
| 311 | + espeak = Popen(cmd_line, stdout=PIPE) |
| 312 | + play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n) |
311 | 313 | play.wait() |
312 | 314 |
|
313 | 315 | def _get_channel(self): |
|
0 commit comments