Skip to content

ev3dev#1026: Sound.speak does not work with double quotes#443

Merged
dwalton76 merged 4 commits intoev3dev:developfrom
amandaoneal:patch-1
Jan 30, 2018
Merged

ev3dev#1026: Sound.speak does not work with double quotes#443
dwalton76 merged 4 commits intoev3dev:developfrom
amandaoneal:patch-1

Conversation

@amandaoneal
Copy link
Copy Markdown
Contributor

No description provided.

@WasabiFan
Copy link
Copy Markdown
Member

@ddemidov In ev3dev/ev3dev#1026 (comment) I suggested using https://docs.python.org/3.4/library/shlex.html#shlex.quote; see the conversation there. Thoughts?

@ddemidov
Copy link
Copy Markdown
Member

@WasabiFan , yes, shlex should work, same as in several other places in sound.py, e.g. here:

return Popen(shlex.split('/usr/bin/beep %s' % args), stdout=n)

@ddemidov
Copy link
Copy Markdown
Member

Corection: not in the same way, since shlex.quote is also needed here. I think something like

cmd_line = '/usr/bin/espeak --stdout {0} "{1}" | /usr/bin/aplay -q'.format(espeak_opts, text)
cmd_args = [shlex.quote(a) for a in shlex.split(cmd_line)]
...
play = Popen(args, stdout=n)

(note the absence of shell=True) should work and would be consistent with the rest of the code.

Copy link
Copy Markdown
Member

@ddemidov ddemidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see if using shlex would work here

@ddemidov
Copy link
Copy Markdown
Member

Final edit:

cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
...
play = Popen(args, stdout=n)

seems to be more reliable and actually does work:

>>> espeak_opts='-a -b -c'
>>> text = 'Hello " world'
>>> cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
>>> cmd_line
['/usr/bin/espeak', '--stdout', '-a', '-b', '-c', '\'Hello " world\'']

@amandaoneal
Copy link
Copy Markdown
Contributor Author

OK, switched over to shlex and tested on my local EV3 setup. Any verdict on if we wanted shell=True in the Popen calls?

Copy link
Copy Markdown
Member

@ddemidov ddemidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think shell=True is not needed if we use shlex.split(). Otherwise, looks good to me.

@dwalton76
Copy link
Copy Markdown
Collaborator

@amandaoneal can you drop the shell=True part? Once that is out it looks good to go. Thanks!

@dwalton76
Copy link
Copy Markdown
Collaborator

@amandaoneal there are some conflicts that have to be resolved before we can merge.

@amandaoneal
Copy link
Copy Markdown
Contributor Author

Looked like the only merge conflict was that the folder 'ev3dev' got renamed 'ev3dev2'... Sigh. Should be back in good shape now.

@dwalton76 dwalton76 merged commit 2de6ece into ev3dev:develop Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants