Created
October 21, 2016 12:15
-
-
Save akx/0917b0aa6ee35e4f6a7795a3a3bfa821 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| # `brew install sox` first | |
| import argparse, tempfile, subprocess, os | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('-v', '--voice', default='Mikko') | |
| ap.add_argument('-p', '--pitch', type=int, default=0) | |
| ap.add_argument('-t', '--tempo', type=float, default=None) | |
| ap.add_argument('-s', '--speed', type=float, default=None) | |
| ap.add_argument('text') | |
| args = ap.parse_args() | |
| fn = tempfile.mktemp(suffix='.aiff') | |
| subprocess.check_call(['/usr/bin/say', '-v', args.voice, '-o', fn, args.text]) | |
| process = [] | |
| if args.pitch != 0: | |
| process.extend(['pitch', '%+d' % args.pitch]) | |
| if args.tempo: | |
| process.extend(['tempo', '%f' % args.tempo]) | |
| if args.speed: | |
| process.extend(['speed', '%f' % args.speed]) | |
| subprocess.check_call(['/usr/local/bin/play', fn] + process) | |
| os.unlink(fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment