在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jishi/node-sonos-http-api开源软件地址:https://github.com/jishi/node-sonos-http-api开源编程语言:JavaScript 90.7%开源软件介绍:The Sonos S2 update, released June 2020, still works with this API. However, it might break in the future if and when Sonos decide to drop UPnP as the control protocol. Feel free to use it as you please. Consider donating if you want to support further development. Reach out on the gitter chat if you have issues getting it to run, instead of creating new issues, thank you! If you are also looking for cloud control (ifttt, public webhooks etc), see the bronos-client project! That pi image also contains an installation of this http-api. SONOS HTTP API** Beta is no more, master is up to date with the beta now! ** This application requires node 4.0.0 or higher! This should now work on Node 6+, please let me know if you have issues A simple http based API for controlling your Sonos system. There is a simple sandbox at /docs (incomplete atm) USAGEStart by fixing your dependencies. Invoke the following command:
This will download the necessary dependencies if possible. start the server by running
Now you can control your system by invoking the following commands:
Example:
The actions supported as of today:
StateExample of a state json:
QueueObtain the current queue list from a specified player. The request will accept:
Example queue response:
PresetA preset is a predefined grouping of players with predefined volumes, that will start playing whatever is in the coordinators queue. Example preset (state and uri are optional):
The first player listed in the example, "room1", will become the coordinator. It will loose it's queue when ungrouped but eventually that will be fixed in the future. Playmode defines the three options "shuffle", "repeat", "crossfade" similar to the state Favorite will have precedence over a uri. pauseOthers will pause all zones before applying the preset, effectively muting your system. sleep is an optional value that enables the sleep timer and is defined in total seconds (600 = 10 minutes). presets.json (deprecated, use preset files instead)You can create a file with pre made presets, called presets.json. It will be loaded upon start, any changes requires a restart of the server. Example content: {
"all": {
"playMode": {
"shuffle": true
},
"players": [
{
"roomName": "Bathroom",
"volume": 10
},
{
"roomName": "Kitchen",
"volume": 10
},
{
"roomName": "Office",
"volume": 10
},
{
"roomName": "Bedroom",
"volume": 10
},
{
"roomName": "TV Room",
"volume": 15
}
],
"pauseOthers": true
},
"tv": {
"players": [
{
"roomName": "TV Room",
"volume": 20
}
],
"pauseOthers": true,
"uri": "x-rincon-stream:RINCON_000XXXXXXXXXX01400"
}
} In the example, there is one preset called
presets folderYou can create a preset files in the presets folder with pre made presets. It will be loaded upon start, any changes made to files in this folder (addition, removal, modification) will trigger a reload of your presets. The name of the file (xxxxxx.json) will become the name of the preset. It will be parsed as JSON5, to be more forgiving of typos. See http://json5.org/ for more info. Example content: {
"players": [
{
"roomName": "Bathroom",
"volume": 10
},
{
"roomName": "Kitchen",
"volume": 10
},
{
"roomName": "Office",
"volume": 10
},
{
"roomName": "Bedroom",
"volume": 10
},
{
"roomName": "TV Room",
"volume": 15
}
],
"trackNo": 3,
"elapsedTime": 42,
"playMode": {
"shuffle": true,
"repeat": "all",
"crossfade": false
},
"pauseOthers": false,
"favorite": "My example favorite"
} There is an example.json bundled with this repo. The name of the file will become the name of the preset. settings.jsonIf you want to change default settings, you can create a settings.json file and put in the root folder. This will be parsed as JSON5, to be more forgiving. See http://json5.org/ for more info. Available options are:
Example: {
"voicerss": "Your api key for TTS with voicerss",
"microsoft": {
"key": "Your api for Bing speech API",
"name": "ZiraRUS"
},
"port": 5005,
"ip": "0.0.0.0",
"securePort": 5006,
"https": {
"key": "/path/to/key.pem",
"cert" : "/path/to/cert.pem"
//... for pfx (alternative configuration)
"pfx": "/path/to/pfx.pfx",
"passphrase": "your-passphrase-if-applicable"
},
"auth": {
"username": "admin",
"password": "password"
},
"announceVolume": 40,
"pandora": {
"username": "your-pandora-account-email-address",
"password": "your-pandora-password"
},
"spotify": {
"clientId": "your-spotify-application-clientId",
"clientSecret": "your-spotify-application-clientSecret"
},
"library": {
"randomQueueLimit": 50
}
} Override as it suits you. Note for Spotify users!To use Spotify, go to https://developer.spotify.com/my-applications/#!/applications/create and create a Spotify application to get your client keys. You can name it Sonos or anything else and you don't have to change any values. Use the Client ID and the Client Secret values in the settings.json file as indicated above. FavoritesIt now has support for starting favorites. Simply invoke:
and it will replace the queue with that favorite. Bear in mind that favorites may share name, which might give unpredictable behavior at the moment. PlaylistPlaying a Sonos playlist is now supported. Invoke the following:
and it will replace the queue with the playlist and starts playing. Say (TTS support)Experimental support for TTS. Today the following providers are available:
It will use the one you configure in settings.json. If you define settings for multiple TTS services, it will not be guaranteed which one it will choose! VoiceRSSThis REQUIRES a registered API key from voiceRSS! See http://www.voicerss.org/ for info. You need to add this to a file called settings.json (create if it doesn't exist), like this:
Replace the code above (it is just made up) with the api-key you've got after registering. Action is:
Example:
language code needs to be before volume if specified. Sayall will group all players, set 40% volume (by default) and then try and restore everything as the way it where. Please try it out, it will probably contain glitches but please report detailed descriptions on what the problem is (starting state, error that occurs, and the final state of your system). The supported language codes are:
MicrosoftThis one also requires a registered api key. You can sign up for free here: https://www.microsoft.com/cognitive-services/en-US/subscriptions?mode=NewTrials and select "Bing Speech - Preview". The following configuration is available (the entered values except key are default, and may be omitted): {
"microsoft": {
"key": "Your api for Bing speech API",
"name": "ZiraRUS"
}
} You change language by specifying a voice name correlating to the desired language. Name should be specified according to this list: https://www.microsoft.com/cognitive-services/en-us/speech-api/documentation/API-Reference-REST/BingVoiceOutput#SupLocales where name is the right most part of the voice font name (without optional Apollo suffix). Example:
Action is:
Example:
Supported voices are: Hoda, Naayf, Ivan, HerenaRUS, Jakub, Vit, HelleRUS, Michael, Karsten, Hedda, Stefan, Catherine, Linda, Susan, George, Ravi, ZiraRUS, BenjaminRUS, Laura, Pablo, Raul, Caroline, Julie, Paul, Cosimo, Ayumi, Ichiro, Daniel, Irina, Pavel, HuihuiRUS, Yaoyao, Kangkang, Tracy, Danny, Yating, Zhiwei See https://www.microsoft.com/cognitive-services/en-us/speech-api/documentation/API-Reference-REST/BingVoiceOutput#SupLocales to identify which language and gender it maps against. If your desired voice is not in the list of supported one, raise an issue about adding it or send me a PR. AWS PollyRequires AWS access tokens, which you generate for your user. Since this uses the AWS SDK, it will look for settings in either Environment variables, the ~/.aws/credentials or ~/.aws/config. You can also specify it for this application only, using: {
"aws": {
"credentials": {
"region": "eu-west-1",
"accessKeyId": "Your access key id",
"secretAccessKey": "Your secret"
},
"name": "Joanna"
}
} Choose the region where you registered your account, or the one closest to you. Polly is only supported in US East (Northern Virginia), US West (Oregon), US East (Ohio), and EU (Ireland) as of today (dec 2016) If you have your credentials elsewhere and want to stick with the default voice, you still need to make sure that the aws config option is set to trigger AWS TTS: {
"aws": {}
} Action is:
Example:
This is the current list of voice names and their corresponding language and accent (as of Dec 2016). To get a current list of voices, you would need to use the AWS CLI and invoke the describe-voices command.
Google (default if no other has been configured)Does not require any API keys. Please note that Google has been known in the past to change the requirements for its Text-to-Speech API, and this may stop working in the future. There is also limiations to how many requests one is allowed to do in a specific time period. The following language codes are supported
Action is:
macOS say commandOn macOS the "say" command can be used for text to speech. If your installation runs on macOS you can activate the system TTS by giving an empty configuration: {
"macSay": {}
} Or you can provide a default voice and a speech rate: {
"macSay": {
"voice" : "Alex",
"rate": 90
}
} Action is:
Example:
Supported voices are: Alex, Alice, Alva, Amelie, Anna, Carmit, Damayanti, Daniel, Diego, Ellen, Fiona, Fred, Ioana, Joana, Jorge, Juan, Kanya, Karen, Kyoko, Laura, Lekha, Luca, Luciana, Maged, Mariska, Mei-Jia, Melina, Milena, Moira, Monica, Nora, Paulina, Samantha, Sara, Satu, Sin-ji, Tessa, Thomas, Ting-Ting, Veena, Victoria, Xander, Yelda, Yuna, Yuri, Zosia, Zuzana A list of available voices can be printed by this command:
See also https://gist.github.com/mculp/4b95752e25c456d425c6 and https://stackoverflow.com/questions/1489800/getting-list-of-mac-text-to-speech-voices-programmatically To download more voices go to: System Preferences -> Accessibility -> Speech -> System Voice Line-inConvenience method for selecting line in. Will select linein for zone-group, not detach it for line-in. Optional parameter is line-in from another player. Examples:
If you want to to isolate a player and then select line-in, use the ClipLike "Say" but instead of a phrase, reference a custom track from the
Examples:
Pro-tip: announce your arrival with an epic theme song! GroupingYou have basic grouping capabilities.
You don't have to ungroup a player in order to join it to another group, just join it to the new group and it will jump accordingly. SUBSUB actions include the following:
|