[HOW-TO] Easily switch audio outputs, settings, etc.
#76
teeedubb you're the man! the script is awesome, thank you for your work. I'm currently using both variations from the first page, for two audio devices and for three. I have a question concerning the later. I have it working perfectly in a machine that has 3 audio devices but I wanted to make it work in another machine to toggle among one audio device and two variations of a second device. I don't know if I'm being clear. I would like the script to change from these 3 options:

-HDMI (passthrough FALSE, stereoupmix 0)
-SPDIF (passsthrough TRUE, stereoupmix 0)
-SPDIF (passsthrough TRUE, stereoupmix 1)

The script I tried looks like this:

#audio toggle script for xbmc
import xbmc
import os

tempdir = xbmc.translatePath('special://temp/')
tempfile0 = os.path.join(tempdir, 'audiooutput0')
tempfile1 = os.path.join(tempdir, 'audiooutput1')

print("CURRENT AUDIO DEVICE:")
print(xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.audiodevice"},"id":1}'))

if not os.path.isfile(tempfile0):
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"ALSA:@"}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.stereoupmix","value":1}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO", "message":"AMPLI UPMIX", "image":"/storage/.kodi/userdata/keymaps/icon.png"}, "id":1}')
file = open(tempfile0, "a")
file.close()
elif not os.path.isfile(tempfile1):
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"ALSA:@"}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.stereoupmix","value":0}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO", "message":"AMPLI", "image":"/storage/.kodi/userdata/keymaps/icon.png"}, "id":1}')
file = open(tempfile1, "a")
file.close()
else:
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"PI:@"}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.stereoupmix","value":0}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO", "message":"TELE", "image":"/storage/.kodi/userdata/keymaps/icon.png"}, "id":1}')
os.remove(tempfile0)
os.remove(tempfile1)

The stereoupmix setting doesn't change and I think it's because I need to add a second condition (the parameter stereoupmix) to the PRINT line and I have no clue how to do that. I'm able to understand the logic of the script but I dont know any programing language. Hope you can help, thanks!
Reply
#77
My girlfriend is using two devices with Windows Kodi- speakers (audio output) and surround headphones (spdif). I'd like to make it easy for her (with a keypress or icon) to switch between outputs. How would I go about this?
Reply
#78
On installing via the one-click installer, right click on the tray icon and select Settings.
Reply
#79
(2016-09-13, 00:28)Wagg Wrote: My girlfriend is using two devices with Windows Kodi- speakers (audio output) and surround headphones (spdif). I'd like to make it easy for her (with a keypress or icon) to switch between outputs. How would I go about this?

Follow the instructions in the first post...

(2016-09-13, 11:42)georgetgonzales Wrote: On installing via the one-click installer, right click on the tray icon and select Settings.

??
Reply
#80
(2016-01-13, 18:59)BartZorn Wrote: I had configured this successfully on Kodi 15.2. Now I am running 16beta5 and the only thing I see in the log is:

WARNING: CPythonInvoker(6): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.

The expected output "CURRENT AUDIO DEVICE" does not appear in the log. After I (re)start Kodi, the notification appears once, at the first time I press the remote button. After that, nothing but the above message in the log.

Is there another requirement in Jarvis to run python scripts?

TIA,

Bart

(2016-01-17, 04:12)teeedubb Wrote: Not sure about any changed requirements in Jarvis, though going by that error message the script should still work. I'll set this up again on my windows machine and test it out.


I am now running Kodi 17beta5, and I still get this message in the log.

Bart
Kodi 18.8, TVMosaic 1.0.0
Digital Devices Cine S2 V7 dual DVB-S tuner with CI
Windows 10 Pro x64
Core i3 CPU, 8 GB memory
Reply
#81
I am trying to see what my current device is and have commented out the execute lines.  When I call the script, I only get a warning printed to my kodi.log.  

Code:
09:35:47.979 T:140070503393024 WARNING: CPythonInvoker(4): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.

1) How can I see what the current audio device should be?
2) Should we worry about the warning in a future release?  Seems like without an addon, the script will not execute at some point.
Need help programming a Streamzap remote?
Reply
#82
That warning has always been there and the script worked even if it was displayed - I dont know what has changed. Wrapping the script up in a addon is simple, but I'll leave that for someone else as I have never personally used this script.
Reply
#83
Thanks for sharing this (y)
Reply
#84
Is it possible to set contrast/brightness levels directly, without openning OSDVideo Settings and so on?
Reply
#85
If it is possible to change those settings via kodis json-rpc interface then yes.
Reply
#86
Thanks @teeedubb for this script. I was very useful to me.
I've modified it to made a simpler script just to toggle audio passthrough with a key of my remote controller
Code:

import xbmc
import json

json_string = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.passthrough"}, "id":1}')
audio_passthrough = (json.loads(json_string))["result"]["value"]
if (audio_passthrough):
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false}, "id":1}')
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO SETTINGS", "message":"Passthrough Disabled"}, "id":1}')
else:
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true}, "id":1}')
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO SETTINGS", "message":"Passthrough Enabled"}, "id":1}')
Reply
#87
(2018-04-11, 15:44)Vardor Wrote: Thanks @teeedubb for this script. I was very useful to me.
I've modified it to made a simpler script just to toggle audio passthrough with a key of my remote controller
Code:

import xbmc
import json

json_string = xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.passthrough"}, "id":1}')
audio_passthrough = (json.loads(json_string))["result"]["value"]
if (audio_passthrough):
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false}, "id":1}')
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO SETTINGS", "message":"Passthrough Disabled"}, "id":1}')
else:
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true}, "id":1}')
  xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO SETTINGS", "message":"Passthrough Enabled"}, "id":1}')

The above is exactly what i need but i’m a script newbie. Do i paste it in keyboard.xml?, and could some kind soul post the exact text i need to paste there to map it to the a key please? I’ve tried this and it always brings up audio offset instead.
Reply
#88
You need to save the above script as a .py file somewhere on your pc, eg c:\audio-switch.py then point your keymap to the script, eg <A>RunScript("c:\audio-switch.py")</A>
Reply
#89
(2020-06-18, 13:52)teeedubb Wrote: You need to save the above script as a .py file somewhere on your pc, eg c:\audio-switch.py then point your keymap to the script, eg <A>RunScript("c:\audio-switch.py")</A>
Worked like a charm, thank you so much!
Reply



Logout Mark Read Team Forum Stats Members Help
[HOW-TO] Easily switch audio outputs, settings, etc.3
This forum uses Lukasz Tkacz MyBB addons.