From e0f4aab257a4a2d4d6bee8ab6397f3ce331243f3 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 6 Oct 2022 20:29:03 +0100 Subject: [PATCH] obs example added. README for obs example added --- examples/obs/README.md | 39 +++++++++++++++++++++++ examples/obs/__main__.py | 69 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 examples/obs/README.md create mode 100644 examples/obs/__main__.py diff --git a/examples/obs/README.md b/examples/obs/README.md new file mode 100644 index 0000000..7d21148 --- /dev/null +++ b/examples/obs/README.md @@ -0,0 +1,39 @@ +## Requirements + +- [OBS Studio](https://obsproject.com/) +- [OBS Python SDK for Websocket v5](https://github.com/aatikturk/obsws-python) + +## About + +Perhaps you have a streaming setup but you want to control OBS and Voicemeeter from a remote location with python installed. +With the vban-cmd and obsws-python packages you may sync a distant Voicemeeter with a distant OBS over LAN. + +The script assumes you have OBS connection info saved in a config file named `config.toml` placed next to `__main__.py`. +It also assumes you have scenes named `START` `BRB` `END` and `LIVE`. + +A valid `config.toml` file might look like this: + +```toml +[connection] +host = "gamepc.local" +port = 4455 +password = "mystrongpass" +``` + +## Use + +Simply fill in the OBS websocket details into `config.toml` and your VBAN text request settings in the script (`ip`, `streamname` and `port`). + +Make sure you have established a working connection to OBS and the remote Voicemeeter. + +Change OBS scenes and watch Voicemeeter parameters change. + +Pressing `` will exit. + +## Notes + +This script can be run from a Linux host since the vban-cmd interface relies on UDP packets and obsws-python runs over websockets. + +You could for exmaple, set this up to run in the background on a home server such as a Raspberry Pi. + +It requires Python 3.10+. diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py new file mode 100644 index 0000000..dd8e55b --- /dev/null +++ b/examples/obs/__main__.py @@ -0,0 +1,69 @@ +import logging + +import obsws_python as obs +import vban_cmd + + +def on_start(): + vban.strip[0].mute = True + vban.strip[1].B1 = True + vban.strip[2].B2 = True + + +def on_brb(): + vban.strip[7].fadeto(0, 500) + vban.bus[0].mute = True + + +def on_end(): + vban.apply( + { + "strip-0": {"mute": True}, + "strip-1": {"mute": True, "B1": False}, + "strip-2": {"mute": True, "B1": False}, + } + ) + + +def on_live(): + vban.strip[0].mute = False + vban.strip[7].fadeto(-6, 500) + vban.strip[7].A3 = True + + +def on_current_program_scene_changed(data): + scene = data.scene_name + print(f"Switched to scene {scene}") + + match scene: + case "START": + on_start() + case "BRB": + on_brb() + case "END": + on_end() + case "LIVE": + on_live() + case _: + pass + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + + kind_id = "potato" + opts = { + "ip": "gamepc.local", + "streamname": "Command1", + "port": 6980, + "subs": {"pdirty": False}, + "sync": True, + } + + with vban_cmd.api(kind_id, **opts) as vban: + cl = obs.EventClient() + cl.callback.register(on_current_program_scene_changed) + + while cmd := input("Press to exit\n"): + if not cmd: + break