sam
sam

Reputation: 115

Subprocess.call how to espeak the components in a list

import subprocess

digit = [1,2,3,4]
subprocess.call('espeak -s 120 -ven ' + str(digit) +'--stdout | aplay', shell=True)

The sound that i hear is only "One", which is only the first component of the list. How should I write the code to make it announce "One-Two-Three-Four"?

Upvotes: 0

Views: 310

Answers (1)

DeepSpace
DeepSpace

Reputation: 81664

Use a loop to iterate over digits (note that I changed the name of the list to digits). While you are at it you may want to use str.format for readability.

import subprocess

digits = [1, 2, 3, 4]
for digit in digits:
    subprocess.call('espeak -s 120 -ven {} --stdout | aplay'.format(digit), shell=True)

Upvotes: 1

Related Questions