Python example?

Python example?

UpstairsericsUpstairserics Member Posts: 10

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?



  • edited 12/18/2017 - 08:02
    Zach@Bose[email protected] Admin Posts: 169

    Hi Upstairserics,

    I actually have a Python example on hand as this is what I use to test/troubleshoot things most often myself - hope this helps:

    import requests
    import xml.dom.minidom
    # set the params:
    ipaddr = "NNN.NNN.NNN.NNN" # enter your speaker IP address here 
    url = "" # enter the URL of the file you want to play here
    service = "That word..." 
    reason = " 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 ='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()
    print responseXML_pretty
  • UpstairsericsUpstairserics Member Posts: 10

    Superb, many thanks. A big accelerator.

  • PepitePepite Member Posts: 3

    Thanks too,
    could the url be replaced by a path like c:/music/bell.mp3?

  • PepitePepite Member Posts: 3

    An other question: Does extension/File have to be mp3?

  • UpstairsericsUpstairserics Member Posts: 10

    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.
    Stay tuned

  • PepitePepite Member Posts: 3

    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)

  • UpstairsericsUpstairserics Member Posts: 10

    My effort using the notification api

  • edited 12/28/2017 - 10:18
    thewildthewild Member Posts: 6

    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)
  • fabnavfabnav Member Posts: 7


    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.



  • edited 02/08/2018 - 07:37
    Zach@Bose[email protected] Admin Posts: 169

    Hi Fabnavigator,

    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.

  • edited 02/08/2018 - 11:38
    fabnavfabnav Member Posts: 7

    Works perfectly with my SoundTouch 20.



Sign In or Register to comment.