Created
May 21, 2013 14:07
-
-
Save ento/5620043 to your computer and use it in GitHub Desktop.
Mac OS X: Ask every voice found by `say -v "?"` to say the demo text.
Note that `say` only returns voices for your system language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """ | |
| Ask every voice found by `say -v "?"` to say the demo text. | |
| Note that `say` only returns voices for your system language. | |
| """ | |
| import time | |
| from subprocess import Popen, PIPE | |
| def say(voice, text): | |
| args = ["say", "-v", voice, text] | |
| p = Popen(args) | |
| p.communicate() | |
| def iter_voices(): | |
| args = ["say", "-v", "?"] | |
| p = Popen(args, stdout=PIPE) | |
| out, err = p.communicate() | |
| for line in out.splitlines(): | |
| name_lang, demo = line.split('#') | |
| elacol, eman = name_lang.strip()[::-1].split(' ', 1) | |
| yield line, eman.strip()[::-1], elacol.strip()[::-1], demo.strip() | |
| def demo_all(): | |
| for line, name, locale, demo in iter_voices(): | |
| print line | |
| say(name, "I'm {}.".format(name)) | |
| time.sleep(1) | |
| say(name, demo) | |
| time.sleep(1) | |
| if __name__ == '__main__': | |
| demo_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment