Hello everyone! I’m having some difficulties getting audio from using ElevenLabs’ API Text to Speech feature. When making the request, I’m getting all as expected:
HTTP/1.1 200 OK
date: Mon, 08 May 2023 09:14:31 GMT
server: uvicorn
request-id: nFk0wHUr0AemKLH4jkTD
history-item-id: 8i2VQJAt1drNC9xtW1OF
access-control-expose-headers: request-id, history-item-id
content-length: 11493
content-type: audio/mpeg
access-control-allow-origin: *
access-control-allow-headers: *
access-control-allow-methods: POST, OPTIONS, DELETE, GET
Via: 1.1 google
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Data size in bytes: 11493
I then take the ‘history-item-id’ key, and try to access the audio through Get Audio from History method and Download History Items with no luck. I’m getting 200 status messages but still no link to access the file:
HTTP/1.1 200 OK
date: Mon, 08 May 2023 09:18:15 GMT
server: uvicorn
content-length: 11493
content-type: audio/mpeg
access-control-allow-origin: *
access-control-allow-headers: *
access-control-allow-methods: POST, OPTIONS, DELETE, GET
Via: 1.1 google
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Data size in bytes: 11493
Does anybody have any experience using this API inside TouchDesigner? Any hints on what may be happening?
Great to hear you got it to work - how did you end up doing it?
The Web Client DAT in combination with an extension can help here a lot.
The attached tox has an extension with 2 important functions: PostRequest() and receiveData()
The PostRequest function builds up a dictionary for the header values and a dictionary for the request data. The request data dictionary needs to be converted to json while the header data is passed to the Web Client DAT as a dictionary:
As you can see, the request Method of the Web Client DAT returns an id which I save into an attribute. This is important as with every response in the the DAT, I receive an id that will match the request. There are a few more things I save into that attribute: content length, length of received data, the data itself, and a filename to where to write the data to.
In the onResponse() callback of the Web Client DAT, I now call the other function: receiveData() and pass all values received by that callback.
In the function itself, I check if my attribute contains a key equal to the id and append the data to it.
Finally, checking if all data has been received, I save out the file and play it with a Audio Play CHOP.
It’s not very clean and should be extended but brings across the point.
To try the file, you need to enter your API key into the custom parameter called “API Key”.
This is great Markus. I am wondering if you know why it fails to grab the entire message at times. I noticed when I trigger a request it often fails about half the time but audio file is created on the elevenlabs website. I tried bypass the data length check to see what is wrong with the received data and it seems to be cutting off the audio file at times which is what I’m guessing makes it fail the check. What would be the best way to re request if the transmission fails?
is it that it disconnects before the full data was received? you could check with the Web Client DAT’s onDisconnect callback .
for debugging probably also good to print the expected and received length with every receiveData
call - something like print(self.reqDict[id]['length'], self.reqDict[id]['received'])