Skip to content

Instantly share code, notes, and snippets.

@illucent
Created March 20, 2014 22:16
Show Gist options
  • Select an option

  • Save illucent/9675115 to your computer and use it in GitHub Desktop.

Select an option

Save illucent/9675115 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: UTF-8
# ARGV[0] - string with text, need to be spoken
# ARGV[1] - filename for new wav file
require 'mechanize'
# retrieve web page with tts
a = Mechanize.new
req = a.get 'http://www2.research.att.com/~ttsweb/tts/demo.php'
# get the form
form = req.forms[0]
# replace with parameter
form['txt'] = ARGV[0]
# set german female voice
form['voice'] = 'reiner' # use 'klara' for female voice
# submit the form
ret = form.submit
# write sound to wav file
File.open(ARGV[1]+'.wav', 'w') {|f| f.write(ret.body) }
# create gsm file for Asterisk
%x[ sox #{ARGV[1]}.wav -r 8000 #{ARGV[1]}.gsm resample -ql ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment