Skip to content

Instantly share code, notes, and snippets.

@AkazaRenn
Forked from snakecase/Beep on replay buffer save.lua
Last active April 3, 2023 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkazaRenn/98871c04daef7130ffa25b3f47bf1dbc to your computer and use it in GitHub Desktop.
Save AkazaRenn/98871c04daef7130ffa25b3f47bf1dbc to your computer and use it in GitHub Desktop.
OBS Lua: Sound notification on screenshot taken & replay buffer save [Windows]

A simple Lua script which plays a .wav sound whenever replay buffer is saved.

Installation

  1. Find your Steam screenshot sound at <SteamInstallFolder>\resource\camera1.wav or use any .wav sound but make sure to match its name in hotkey-play-sound.lua (edit with any text editor)

  2. Put it in the folder named hotkey-play-sound which locates with hotkey-play-sound.lua. A good way is to create a separate scripts folder in %AppData%\obs-studio\ and keep all your scripts there in case you need to backup your OBS Settings.

  3. OBS -> Tools -> Scripts -> +

  4. OBS -> Settings -> Hotkey, find the new hotkey and register your preferred key combinations. It's possible to register a used hotkey to achieve "play sound when saving replay buffer" like effect

Credits:

Thank you guys!

local obs = obslua
local ffi = require("ffi")
local winmm = ffi.load("Winmm")
hotkey_id = obs.OBS_INVALID_HOTKEY_ID
-- Unique ID for the hotkey in settings file
HOTKEY_UNIQUE_ID = "play_screenshot_vfx"
-- Hotkey description in Settings GUI
HOTKEY_DESCRIPTION = "Play Screenshot VFX"
-- Put a sound of your choosing next to "Beep on replay save.lua" and don't forget to match its name either in code below or rename your file.
PROP_AUDIO_FILEPATH = script_path() .. "hotkey-play-sound/camera1.wav"
ffi.cdef[[
bool PlaySound(const char *pszSound, void *hmod, uint32_t fdwSound);
]]
function play_sound(pressed)
if (pressed) then
winmm.PlaySound(PROP_AUDIO_FILEPATH, nil, 0x00020003)
end
end
function script_load(settings)
hotkey_id = obs.obs_hotkey_register_frontend(HOTKEY_UNIQUE_ID, HOTKEY_DESCRIPTION, play_sound)
local hotkey_save_array = obs.obs_data_get_array(settings, HOTKEY_UNIQUE_ID)
obs.obs_hotkey_load(hotkey_id, hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end
function script_save(settings)
local hotkey_save_array = obs.obs_hotkey_save(hotkey_id)
obs.obs_data_set_array(settings, HOTKEY_UNIQUE_ID, hotkey_save_array)
obs.obs_data_array_release(hotkey_save_array)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment