Hi learned folk,
Does anyone have a primitive example of a python/requests integration with this api to save me the pain of working this out from scratch?
I actually have a Python example on hand as this is what I use to test/troubleshoot things most often myself - hope this helps:
# set the params:
ipaddr = "NNN.NNN.NNN.NNN" # enter your speaker IP address here
url = "http://www.nasa.gov/mp3/590331main_ringtone_smallStep.mp3" # enter the URL of the file you want to play here
service = "That word..."
reason = "...it does not mean..."
message = "...what you think it means."
key = "abcdefghijklmnop1234567890" # enter your API key here
volumeVal = "20" # enter volume here, a number between 10 and 70
# form and send the /speaker POST request
sendXML = "<play_info><app_key>" + key + "</app_key><url>" + url + "</url><service>" + service + "</service><reason>" + reason + "</reason><message>" + message + "</message><volume>" + volumeVal + "</volume></play_info>"
send = requests.post('http://' + ipaddr + ':8090/speaker', data=sendXML)
# print a pretty version of the response - not required but can be helpful for reading errors if they occur
responseXML = xml.dom.minidom.parseString(send.text)
responseXML_pretty = responseXML.toprettyxml()
Superb, many thanks. A big accelerator.
could the url be replaced by a path like c:/music/bell.mp3?
An other question: Does extension/File have to be mp3?
In the use case where we want to interrupt the playing stream with a 'notification' (think...the mp3 output file from a TTS operation) then not having to run a web server to serve up the file would be useful.
I've got the example above working ok, so I'm going to try a file path but for some reason I'm not expecting it to work.
i can stream all i want Thanks! Now i'm thinking about the 3s lag (i have to put a lag on my computer to hear the music on the same time on the soundtouch)
My effort using the notification api
I can answer this one. As per the API documentation :
Supported file types:
MP3 - 8kbit/s to 320kbit/s
AAC - 24kbit/s to 128kbit/s
HE-AAC - 48kbit/s to 64kbit/s
WMA - 8kbit/s to 320kbit/s
Vorbis - 32kbit/s to 500kbit/s
FLAC - VBR: 0bit/s to 1.4Mbit/s; up to CD quality (2 channel / 48kHz / 16bit)
ALAC - 300kbit/s to 5Mbit/s; HD (2 channel / 96kHz / 32 bit)
I tried that example and this is what I get: '<?xml version="1.0" ?>\n<Error name="HTTP_STATUS_FORBIDDEN" severity="Unknown" value="403">unsupported device</Error>\n'
Could it be my API key isn't good? I used the consumer key for an app I created. This message didn't sound so good: Below are keys you can use to access the API products associated with this application (Test). The actual keys need to be approved and approved for an API product to be capable of accessing any of the URIs defined in the API product.
'<?xml version="1.0" ?>\n<Error name="HTTP_STATUS_FORBIDDEN" severity="Unknown" value="403">unsupported device</Error>\n'
Below are keys you can use to access the API products associated with this application (Test). The actual keys need to be approved and approved for an API product to be capable of accessing any of the URIs defined in the API product.
That error is returned when attempting to use Audio Notifications on a SoundTouch product that does not yet support the capability. The only supported products today are SoundTouch 10, SoundTouch 20 Series III, and SoundTouch 30 Series III - sending a POST to /speaker for any product other than one of those three will return the 403 error you are seeing. Can you confirm you are using one of those three products? If you are, we can look to troubleshoot further.
By the way, if your API key is not good, you would receive a 401 HTTP_STATUS_UNAUTHORIZED error rather than the 403 HTTP_STATUS_FORBIDDEN error you are seeing, so I believe your key is OK.
Works perfectly with my SoundTouch 20.