Text-to-Speech

FREE
By voicerss | Updated 9 days ago | Media
Popularity

9.8 / 10

Latency

949ms

Service Level

100%

Health Check

N/A

Back to All Discussions

How to do I get handle response from API

Rapid account: Valentin
valentin
10 years ago

Hello,

I am super green to working with API and Python, so please bare with me.
I want to write a script that will take in user input (basic word, or phrase). Given that input I want to send it to the Text-2-Speech API and have whatever the user inputed repeated but in audio… Sounds like it should be easy. I am fine all the way up to how to implement the API

I have installed the unirest library, however I don’t know where to go from here…
This my code is

url = “https://voicerss-text-to-speech.p.mashape.com/?key=the site key”

headers = {
“X-Mashape-Authorization”: “they key”,
“content-type”: “binary”
}

parameters = {
“src”: “Hello”,
“hl”: “en-us”,
“r”: 0,
“c”: “mp3”,
“f”: “8khz_8bit_mono”
}

#Called to handle response from url request

def callback(response):
print(response.code) # The HTTP status code
print(response.headers) # The HTTP headers
print(response.body) # The parsed response

response = unirest.post(url, headers, parameters, callback) defined

When I run it return with the headers and a 200 code so I am guessing the request is going through, and Its returning the response… So the question left is… how do I download or work with the response to hear the sound, or donwload the file?

All help truly appreciated

Rapid account: Valentin
valentin Commented 10 years ago

Thank you for the links Chris, I am sure they will come in handy, however I can’t seem to make the connection on how to implement them.

I updated my above post to hopefully explain what my issue is more clearly. The main problem is that once I send my POST request it returns a response which I have no idea how to handle. I don’t know filename, The URL does not point to a file directly as far as I can tell, and this I am lost as to how to use the urllib2, or other library methods to download the file. Please help me out some more… I feel like I am close

Rapid account: Community
community Commented 10 years ago

Hey Valentin, you might want to check these 2 resources on using urllib for python - http://rest.elkstein.org/2008/02/using-rest-in-python.html and http://python.dzone.com/articles/how-download-file-python Let me know if it works for you - chris@mashape.com

Join in the discussion - add comment below:

Login / Signup to post new comments