Created
July 31, 2013 21:39
-
-
Save jwatson/6126434 to your computer and use it in GitHub Desktop.
Sample NDev TTS application.
This file contains 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 | |
#vim: set fileencoding=utf8 | |
""" | |
This example depends on the `requests` library | |
http://requests.readthedocs.org/en/latest/ | |
$ pip install requests | |
""" | |
from __future__ import print_function | |
import random | |
import requests | |
import time | |
APP_ID = "" | |
APP_KEY = "" | |
def main(): | |
headers = { | |
'Accept': "audio/x-wav;codec=pcm;bit=16;rate=22000", | |
'Content-Type': "text/plain", | |
} | |
params = { | |
'appId': APP_ID, | |
'appKey': APP_KEY, | |
'id': "d872Oki9", | |
'ttsLang': "en_US", | |
'voice': "Samantha", | |
} | |
session = requests.session() | |
session.headers.update(headers) | |
session.params = params | |
url = "https://tts.nuancemobility.net/NMDPTTSCmdServlet/tts" | |
text = "This is test {}.".format(random.randint(0, 10000)) | |
for i in xrange(0, 100): | |
print("Attempt {0}... ".format(i + 1), end="") | |
t0 = time.time() | |
r = session.post(url, data=text) | |
t1 = time.time() | |
print("{} ({}s)".format(r.status_code, round(t1 - t0, 2))) | |
r.raise_for_status() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment