Skip to content

Instantly share code, notes, and snippets.

@akx
Created October 21, 2016 12:15
Show Gist options
  • Select an option

  • Save akx/0917b0aa6ee35e4f6a7795a3a3bfa821 to your computer and use it in GitHub Desktop.

Select an option

Save akx/0917b0aa6ee35e4f6a7795a3a3bfa821 to your computer and use it in GitHub Desktop.
#!/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