[APP][Pro] Sonos (LocalAPI)

I don’t experience this behavior/cannot reproduce it. When a favorite radio station is playing and I start a different one via the flowcard, it just starts playing that radio station. I am using Sonos Radio as music service.

But also if I start off by playing a radio station from TuneIn and then use the flowcard to switch to a favorite radio station from Sonos Radio, it switches to that radio station and starts playing.

1 Like

Finally found the cause. Another flow (150 in total!) was causing the unwanted playback behavior on my Sonos, which only affected the Playbar.

Case closed.

1 Like

Nice app, great work!

I have several different speakers, and most of them working fine. Only one I having trouble with are the Sonos Roam 2. getting the following when I’m trying to pause / play etc.

upnp: statusCode 500 & upnpErrorCode <s:Envelope xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/” s:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”><s:Body><s:Fault>s:ClientUPnPError701</s:Fault></s:Body></s:Envelope>

Hi @xiutit !

I’ve completely migrated everything over to your app and it’s been amazing so far, thank you for your hard work.

One “bug” I’ve found (I’m not sure it’s a bug because the behavior might be intentional) is that your app does something different in comparison to the older Homey Sonos app, when executing something like this:

Imagine “Favourites” has about 500 songs in it.

The older Homey Sonos app would play these 500 songs exclusively and then finish (and thus shuffling these songs would only shuffle the 500 songs in the “Favourites” playlist).

Your app seems to add the selected “Favourites” list to the existing Sonos song queue! In practice this for example means that, after first running another unrelated playlist with about 500 songs (let’s say: “Made in Belgium”), when playing “Favourites” the Sonos queue becomes 1000 songs big and “Shuffle on” shuffles not only the “Favourites” playlist but also the previously played “Made in Belgium” playlist as well (so 1000 songs, and potentially all the songs ever queued this way before).

Am I missing something in how I should be using the play favourite flow card or the shuffle on card?

I’m a bit stuck now because I have these “Top 50” playlists that are in a very specific song order that I would like to play and shuffle, but whenever I play them (as a favourite) they get shuffled with all the favourites I’ve ever started this way before, which is not really what I’m going for when playing a very specific playlist.

This problem might be a bit obscure so I hope I’m explaining this right!

I wonder if this app should just copy the behavior from the older Homey Sonos app: so replace the entire queue with the selected favourite. But maybe there is a use case where you want to add a favourite to the queue and not play it exclusively?

Another solution could be adding a specific “clear Sonos playlist que” command, I can do this from the iOS app so perhaps it’s also possible trough the API?

Let me know what you think!

Please don’t unnecessarily inflate the app’s size. :wink:

On my HP26 model with a restart every night it isimage

:roll_eyes:

I have 8 Sonos speakers in my house. Some of them are linked to Flows over 30 times.

Maybe that’s why?

Does “Speak …” only work with an Azure (TTS) account?

I have five Sonos speakers and quite some Sonos related flows. Try restarting Homey and then checking its memory usage. Please let know if there is a different memory usage.

I use a Homey script to generate a Microsoft voice. You can select your voice, speed and style. I send the result to Sonos with the Url card.

TTS - But it’s easier with the original Sonos app… :roll_eyes:
I just noticed that now.
I’ve already transferred about 20 flows to the Sonos API app. :face_with_peeking_eye:

after homey-Reboot:

after 15min +15MB …

after Reboot the App -10MB …

I think I’ll go back to the original Sonos app for now.
I really don’t like the Azure thing (credit card, address, etc.).
Then there’s the RAM requirement.
I’ll keep an eye on it.
Sorry :neutral_face:

Memory leak in the app?

Interesting. Will try to find out where this is coming from.

I understand, but unfortunately these services come at a cost. Homey can cover this from their product revenue, but for developers it’s not possible to ask for a contribution to cover these costs (and I don’t think that would be desirable either)

In v1.7.2 I’ve added a Clear queue flow card. This clears the current queue.

I’m not entirely sure if this is the ideal behavior yet. Right now, Play Favorite and Play Playlist will still start playing immediately, but they add to the queue instead of clearing it first.

One possible improvement could be to introduce separate flow cards:

  • Play Playlist / Play Favorite (which first clears the queue)
  • Add Playlist / Add Favorite (which only adds items to the queue)

For now, the Clear queue flow card at least provides a way to clean up the queue beforehand.

3 Likes

Hi @Amersfoort, could you possibly explain this and provide the code?

How to use Microsoft voices combined with Sonos speakers Options: voice, speaking speed, pitch, langauge.
I made a combination of advanced flow and Homey script. Azure account with a Speech services key needed.

There are multiple alternatives, but this is mine:

  • step 1: Homey script (see below) creates a mp3 variabele
  • step 2: app “FTP client” creates with Micro web server app a mp3 file for the Homey device
  • step 3: Micro web server creates an url for this mp3 file (see app setup here)
  • step 4: play this Cloud url with Sonos (local api) app.

Create in Microsoft Azure a key for speech services. Use this TTS key in Homey script below. Try different Microsoft voices and languages here.

This is the Homey script based on my use case (I’m not a developer and it works for me):

//read a flow variable (text type), here the variabele is 
//called TTSAfTeSpelen.
//This variabele contains the text to play on Sonos
let Variabelen = await Homey.logic.getVariables();
let sNieuwsVariabele = _.find(Variabelen, (object) => object.name === "TTSAfTeSpelen");


// Fallback for empty or not existing variable
let mijnTekst = sNieuwsVariabele ? sNieuwsVariabele.value : "Geen nieuws gevonden"; 

//SSML commands can't escape texts: 
//replace ampersand (&) with "and" (in my case "en")
mijnTekst = mijnTekst.replaceAll("&", " en ");

//Call TTS (Text To Speech) in Azure Cognitive Services
//mp3 format audio-48khz-96kbitrate-mono-mp3: nice sound on Sonos speakers
//and small size
//NL language: lang='nl-NL'
//voice: en-US-JennyMultilingualNeural (see Microsoft TTS setting).
//this is a US base voice, 
//but can be used in multiple languages without accents.
//narration-professional: speaking style (for news messages)
//prosody rate='-10%': speed, in my case 10% less than standard speed
//pitch='0%': default voice pitch
const antwoord = await fetch(
  'https://northeurope.tts.speech.microsoft.com/cognitiveservices/v1',
  {
    method: "POST",
    headers: {
      "Ocp-Apim-Subscription-Key": 'fill here your Azure tts key',
      "Content-Type": "application/ssml+xml",
      "X-Microsoft-OutputFormat": "audio-48khz-96kbitrate-mono-mp3"
    },
    body:
      "<speak xmlns='http://www.w3.org/2001/10/synthesis' " +
      "xmlns:mstts='http://www.w3.org/2001/mstts' version='1.0' xml:lang='nl-NL'>" +
        "<voice name='en-US-JennyMultilingualNeural'>" +
          "<lang xml:lang='nl-NL'>" +
            "<mstts:express-as style='narration-professional' styledegree='3'>" +
              "<prosody rate='-10%' pitch='0%'>" +
                mijnTekst +
              "</prosody>" +
            "</mstts:express-as>" +
          "</lang>" +
        "</voice>" +
      "</speak>"
  }
);

// check TTS call
if (!antwoord.ok) {
    throw new Error("TTS-aanroep mislukt met status: " + antwoord.status + " " + antwoord.statusText);
}

// Get TTS buffer (this is raw data, not yet base64 format needed for Sonos)
const ttsBuffer = await antwoord.buffer();

// announcement sound (Base64 string), created after convert mp3 to base64
const aankondigingsgeluidBase64 = '//OAxAAAAAAAAAAAAFhpbmcAAAAPAAAAGgAAD3UAFRUVJycnJzExMTE6Ojo6Q0NDQ1hYWFhnZ2dubm5udXV1dZiYmJihoaGhqqqqqrOzs7y8vLzFxcXFzMzMzNPT09Pa2tra4ODg4Ofn5+zs7Ozx8fHx9/f39/r6+vr+/v7+////AAAAFExBTUUzLjEwMARuAAAAAAAAAAAVCCQELiEAAaQAAA91nIoTgwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/zoMQAC6ACml9AAAASQCgDDGbh0agQKHOH//y4f/l3/nCjhP//y58oGIYg/wQd/rh/Jlz//4P/4Yg+9X8AAytssu1LvQAMzAEARABcCMCQMl+0yWmLBxUBQM7mDIR1hgNAEPkQy5wsAytsEYgRWIimZEBAHmjLpxrcWoK7D2au7GoFkkYWGWGnXb3BtXO1g+jqRCpTXnKi0BX6XOKUD+PxTFzFQJWarWtTyCMa3/F24chs0iDGsXZRUmPeZ980B2SrzfWTtx5T5FglvpfCYjXsfv9a/m/7lvm+/lvff////w/8vz3v///qcfvJdi9nUpIvnuN5c5qk1HXJi5oAyqVY1sohY+vbk1mikJK2H3NCszd7B0njvSliL86qWJZz6kUttIex+5uH4fpbVJh//NSC3hdps9wQnWr/85DE/UZsErp/m8kE3S+k5jn//9V6igv86fkxTvEHGg7x+35lVa1q9SKgAA27YjnANWorj9x/nmdcGwEjalsJud/d3n3+cvY7xd3fUk6KtFJVJfRQSWrq7f1si1NkkiaIEXgmYF5IKJ1NRyi4VS6TxSWZF4hxsddW3//q/9X+r/X1IPk8xqXSOG2J7IQ3ah/71JOZf+ru+s0f//TbRKxgQUdQg8ZUSMeQiCgLVZzIAEHeH7H0BB5Wta1lVvP0hyE6osCuRyKS0gIqHMPq8hxvnbKvM720X/66m9OTlgPoE6kLMpG5QRKLHDZaJ5JJSl0W9el//+v/TV/9XYuqc1YlxaBl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6zReyXm7U1MGR7ClSWaccVJl92/rzygShYP0////nSM8///zQMTwFRqOnl5pWrz/2f/+7/8uB00akC3gAN/QA/MloThTJoPjJuHpMly4tmU+qm1//QizMcb1M9zWY52//6es9igkAAgVMN1X///+Pf//////+oFVFqBF4FEXrAHtDIoTougP3Vky//MwxPYUMpKaXoBa2BeYUs01TNSIidm//6/////RyhxC+3+pAmcaav/Rm3/zhFCoCtEtO//WHP///////FkWAAbAAOeEAetN1Lcri8HP//NAxOYUqo6aXgvUTJuUARpauumxrZa3Sb/8hZ/Zk+yGObX/7VT/VZYIn//93///////Uh8QFxgBMPAB/yifVKZNSCGdsEQZ9Lr97P/7f//////2IpcmncxMxh9jv///9DRIBaCRZBD/8zDE7g/ijqZeaA8M//WPYFAIGAgAAAAgr5IHngTAEvAUbqJyo/////7P/5FMQU1FMy4xMDCqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr/8zDE7xCyEp5eC9RIqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr/8zDE7Q2qDp5egBUMqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr/8yDE9w3CEqZfSzgAqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//MgxOcHQFqiUYpgAKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv/zEMTxAAADSAHAAACqqqqqqqqqqqqqqqqq';

//cancatenate announcement and TTS variabele to flow. 
//This variabele can be used in the next flow step
return aankondigingsgeluidBase64 + ttsBuffer.toString('base64');
1 Like

From your previous posts, I had interpreted that you don’t need an Azure account. Unfortunately, that is not the case.
For now, I will create an Azure account and experiment with it. Perhaps I will come back to your script later.
Nevertheless, thank you for the information.

I’ve been waiting for someone to do this for so long. Thanks for creating this app! I’ve also noticed this app can do more advanced things than the official app, i’ve wanted Homey to control night sound and speech enhancement on my Beam. But it was impossible since the official app didn’t support that.

Can i ask what is “Balance”?

There’s a Balance thing on my Sonos Beam and i’m not home to check what it is. Is it Left/Right or??

Yes (if supported by your device).

1 Like

Ooo, thanks! But do you know if it’s possible to make the Beam with the surrounds say something? Instead of them speaking individually i would like them all to speak as one speaker.

If those speakers are not joined as one system, then you can group speakers using the group flowcard. That will synchronize playback.

1 Like