From 7d8a1ce1f57c1eadbb0f1335bab32ab698f7ce4f Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Sat, 2 Jul 2022 02:23:22 +0100 Subject: [PATCH] obs example added --- examples/obs/README.md | 19 +++++++++++++++ examples/obs/__main__.py | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 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..a84c366 --- /dev/null +++ b/examples/obs/README.md @@ -0,0 +1,19 @@ +## Requirements + +- [OBS Studio](https://obsproject.com/) +- [OBS Websocket Plugin](https://obsproject.com/forum/resources/obs-websocket-remote-control-obs-studio-from-websockets.466/) +- [OBS Websocket Py](https://github.com/onyx-and-iris/obs-websocket-py) + +## About + +A simple demonstration showing how to sync OBS scene switches to Voicemeeter states. The script assumes you have connection info saved in +a config file named `config.ini` placed next to `__main__.py`. It also assumes you have scenes named `START` `BRB` `END` and `LIVE`. + +A valid `config.ini` file might look like this: + +```ini +[connection] +ip=localhost +port=4444 +password=mystrongpassword +``` diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py new file mode 100644 index 0000000..83e4c55 --- /dev/null +++ b/examples/obs/__main__.py @@ -0,0 +1,50 @@ +import logging +import sys + +import voicemeeterlib + +logging.basicConfig(level=logging.INFO) + +sys.path.append("../") +from obswebsocket import events, obsws + + +def on_start(): + vm.strip[0].mute = True + + +def on_brb(): + vm.strip[7].fadeto(0, 500) + + +def on_end(): + vm.strip[0].mute = True + + +def on_live(): + vm.strip[0].mute = False + vm.strip[7].fadeto(-6, 500) + + +def on_switch(message): + scene = message.getSceneName() + match scene: + case "START": + on_start() + case "BRB": + on_brb() + case "END": + on_end() + case "LIVE": + on_live() + case _: + pass + + +with voicemeeterlib.api("potato") as vm: + with obsws() as ws: + ws.register(on_switch, events.SwitchScenes) + + while cmd := input("Press to exit\n"): + if not cmd: + break