Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions ev3dev2/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import os
import re
import shlex
from subprocess import check_output, Popen
from subprocess import check_output, Popen, PIPE


def _make_scales(notes):
Expand Down Expand Up @@ -294,20 +294,22 @@ def speak(self, text, espeak_opts='-a 200 -s 130', volume=100, play_type=PLAY_WA
self.set_volume(volume)

with open(os.devnull, 'w') as n:
cmd_line = '/usr/bin/espeak --stdout {0} "{1}" | /usr/bin/aplay -q'.format(
espeak_opts, text
)
cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
aplay_cmd_line = shlex.split('/usr/bin/aplay -q')

if play_type == Sound.PLAY_WAIT_FOR_COMPLETE:
play = Popen(cmd_line, stdout=n, shell=True)
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait()

elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE:
return Popen(cmd_line, stdout=n, shell=True)
espeak = Popen(cmd_line, stdout=PIPE)
return Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)

elif play_type == Sound.PLAY_LOOP:
while True:
play = Popen(cmd_line, stdout=n, shell=True)
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait()

def _get_channel(self):
Expand Down