Created
July 20, 2013 11:34
-
-
Save atodorov/6044724 to your computer and use it in GitHub Desktop.
Example how to use SpeakVolumes.eu Text-to-Speech API
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 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