Skip to content

Instantly share code, notes, and snippets.

@atodorov
Created July 20, 2013 11:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save atodorov/6044724 to your computer and use it in GitHub Desktop.
Save atodorov/6044724 to your computer and use it in GitHub Desktop.
Example how to use SpeakVolumes.eu Text-to-Speech API
#!/usr/bin/env python
import os
import sys
import base64
import hashlib
from suds.client import Client as SOAPClient
myusername = 'YourUserName'
mypassword = 'YourSecretPassword'
# text files or strings are accepted as arguments
if len(sys.argv) != 2:
print "Usage: %s <text> | <filename>" % sys.argv[0]
sys.exit(1)
TEXT = sys.argv[1]
JOB_NAME = hashlib.md5(TEXT).hexdigest()
FILE_NAME = JOB_NAME
# if argument is a file, not string
if os.path.exists(TEXT):
JOB_NAME = os.path.basename(TEXT)
f = open(TEXT, 'r')
TEXT = f.read()
f.close()
FILE_NAME = JOB_NAME.replace('.txt', '')
TEXT = TEXT.strip().decode('UTF8', 'ignore')
print "DEBUG: %s, %s, %s" % (JOB_NAME, FILE_NAME, TEXT)
client = SOAPClient('http://api.speakvolumes.eu/vserver.php?wsdl')
# TODO: change 'irina' to the voice of your choice. Irina speaks Bulgarian.
audio = client.service.wsTtS(myusername, mypassword, JOB_NAME, TEXT, 'irina', 0)
audio = base64.b64decode(audio['data'])
mp3 = open('%s.mp3' % FILE_NAME, 'wb')
mp3.write(audio)
mp3.close()
credits = client.service.queryCredits(myusername, mypassword)
print "REMAINING CREDITS: %s", credits['data']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment