[HOW-TO] Easily switch audio outputs, settings, etc. - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33) +--- Forum: Tips, tricks, and step by step guides (https://forum.kodi.tv/forumdisplay.php?fid=110) +--- Thread: [HOW-TO] Easily switch audio outputs, settings, etc. (/showthread.php?tid=199579) |
RE: [HOW-TO] Easily switch audio outputs, settings, etc. - c_g_f - 2016-04-19 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! RE: [HOW-TO] Easily switch audio outputs, settings, etc. - Wagg - 2016-09-13 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? RE: [HOW-TO] Easily switch audio outputs, settings, etc. - georgetgonzales - 2016-09-13 On installing via the one-click installer, right click on the tray icon and select Settings. RE: [HOW-TO] Easily switch audio outputs, settings, etc. - teeedubb - 2016-09-13 (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. ?? RE: [HOW-TO] Easily switch audio outputs, settings, etc. - BartZorn - 2016-11-14 (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: (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 RE: [HOW-TO] Easily switch audio outputs, settings, etc. - graysky - 2017-10-15 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. RE: [HOW-TO] Easily switch audio outputs, settings, etc. - teeedubb - 2017-10-27 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. RE: [HOW-TO] Easily switch audio outputs, settings, etc. - Casey_Dilworth - 2017-11-03 Thanks for sharing this (y) RE: [HOW-TO] Easily switch audio outputs, settings, etc. - routir - 2017-11-07 Is it possible to set contrast/brightness levels directly, without openning OSDVideo Settings and so on? RE: [HOW-TO] Easily switch audio outputs, settings, etc. - teeedubb - 2017-11-07 If it is possible to change those settings via kodis json-rpc interface then yes. RE: [HOW-TO] Easily switch audio outputs, settings, etc. - Vardor - 2018-04-11 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:
RE: [HOW-TO] Easily switch audio outputs, settings, etc. - captainfearless - 2020-06-18 (2018-04-11, 15:44)Vardor Wrote: Thanks @teeedubb for this script. I was very useful to me. 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. RE: [HOW-TO] Easily switch audio outputs, settings, etc. - teeedubb - 2020-06-18 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> RE: [HOW-TO] Easily switch audio outputs, settings, etc. - captainfearless - 2020-06-18 (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! RE: [HOW-TO] Easily switch audio outputs, settings, etc. - graysky - 2021-05-20 @teeedubb - On my system, switching between the TV's internal speakers and an optical out use: hdmi:CARD=HDMI,DEV=1 for the TViec958:CARD=PCH,DEV=0 for the sound barI defined these in the script but upon executing the script, it sets the value to hdmi:CARD=HDMI,DEV=0 NOT to hdmi:CARD=HDMI,DEV=1 Any thoughts? Code: #!/usr/bin/env python3 |