Skip to content

Instantly share code, notes, and snippets.

@snakecase
Forked from upgradeQ/beep.lua
Last active May 29, 2025 18:00
Show Gist options
  • Save snakecase/e816384a071cec31efbb4b9e429c108d to your computer and use it in GitHub Desktop.
Save snakecase/e816384a071cec31efbb4b9e429c108d to your computer and use it in GitHub Desktop.
OBS Lua: Sound notification on replay buffer save [Windows]

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

Installation

  1. Download Half-Life 2 City Scanner NPC's camera shutter sound: https://github.com/sourcesounds/hl2/blob/master/sound/npc/scanner/scanner_photo1.wav

    • Or use any .wav sound but make sure to match its name either in "Beep on replay buffer save.lua" (edit with any text editor) or rename your .wav file to "sound_npc_scanner_scanner_photo1.wav".
  2. Put it in the same location with "Beep on replay buffer save.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 → +

This Lua script was downloaded from https://gist.github.com/snakecase/e816384a071cec31efbb4b9e429c108d

Credits:

Thank you guys!

local obs = obslua
local ffi = require("ffi")
local winmm = ffi.load("Winmm")
-- 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() .. "sound_npc_scanner_scanner_photo1.wav"
ffi.cdef[[
bool PlaySound(const char *pszSound, void *hmod, uint32_t fdwSound);
]]
function playsound(filepath)
winmm.PlaySound(filepath, nil, 0x00020000)
end
function on_event(event)
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED
then playsound(PROP_AUDIO_FILEPATH)
end
end
function script_load(settings)
obs.obs_frontend_add_event_callback(on_event)
end
-- This Lua script was downloaded from https://gist.github.com/snakecase/e816384a071cec31efbb4b9e429c108d
-- Credits: upgradeQ (https://gist.github.com/upgradeQ/b2412242d76790d7618d6b0996c4562f), gima (https://gitlab.com/gima/obsnotification)
-- Thank you guys!
@S4adam
Copy link

S4adam commented Jan 28, 2025

@khezuu which most likely means it can't find the audio file. Make sure you put it next to the script (where the OBS stores it):
Windows: C:\Users\<user>\AppData\Roaming\obs-studio

@iAxed
Copy link

iAxed commented Apr 17, 2025

how do I make the audio quieter?

@NateLapT
Copy link

how do I make the audio quieter?

use audacity

@schniti269
Copy link

oh that makes sense! It does sound familiar. I don't use SteamVR but it might even be Steam's default screenshot sound effect, now that I think about it...

it is the steam screenshot sound by default

@superspeed500
Copy link

Thanks for providing this code! This code also works on Fedora linux (Gnome) if its modified as following.

local obs = obslua
local ffi = require("ffi")

-- 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() .. "sound_npc_scanner_scanner_photo1.wav"

ffi.cdef[[
    bool PlaySound(const char *pszSound, void *hmod, uint32_t fdwSound);
]]

function playsound(filepath)
    os.execute("/usr/bin/play " .. filepath)
end

function on_event(event) 
  if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED 
    then playsound(PROP_AUDIO_FILEPATH) 
  end 
end

function script_load(settings)
  obs.obs_frontend_add_event_callback(on_event)
end

-- This Lua script was downloaded from https://gist.github.com/snakecase/e816384a071cec31efbb4b9e429c108d

-- Credits: upgradeQ (https://gist.github.com/upgradeQ/b2412242d76790d7618d6b0996c4562f), gima (https://gitlab.com/gima/obsnotification)
-- Thank you guys!
-- Modified by Superspeed500 to work on Linux. Requires the package sox.

The package sox is required for the play command to work.
sudo dnf install sox

Will probably work on other distros also, but I only have Fedora, so thats what I have tested :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment