<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Websocket | Tobias Theel | Senior Software Engineer</title><link>https://blog.noobygames.de/tags/websocket/</link><description>Remote-first Senior Software Engineer specializing in Go, Cloud-Native architecture, and Game Development. 12+ years of experience in distributed environments.</description><generator>Hugo</generator><language>en</language><copyright>© 2026 Tobias Theel</copyright><lastBuildDate>Wed, 25 Nov 2026 08:00:00 +0100</lastBuildDate><atom:link href="https://blog.noobygames.de/tags/websocket/index.xml" rel="self" type="application/rss+xml"/><item><title>Building Neuroclip — Part 3: OBS Regie — WebSocket, audio meters and the mute alarm</title><link>https://blog.noobygames.de/blog/neuroclip-3-obs-regie/</link><pubDate>Wed, 25 Nov 2026 08:00:00 +0100</pubDate><dc:creator>Tobias Theel</dc:creator><guid isPermaLink="true">https://blog.noobygames.de/blog/neuroclip-3-obs-regie/</guid><category>Software Engineering</category><category>go</category><category>obs</category><category>obs-websocket</category><category>websocket</category><category>streaming</category><category>audio</category><category>sha256</category><category>neuroclip</category><category>software-engineering</category><description>How a Go service talks to OBS over obs-websocket v5: the SHA-256 handshake, audio meters in dB, and the idea behind a mute alarm that hears speech.</description><content:encoded><![CDATA[<blockquote>
<p><strong>Building Neuroclip, part 3 of 5.</strong> The series: <a href="/blog/neuroclip-1-architecture/">Part 1: Architecture</a> · <a href="/blog/neuroclip-2-vod-to-short-pipeline/">Part 2: VOD to short pipeline</a> · <strong>Part 3: OBS Regie</strong> · <span class="link-upcoming">Part 4: Facecam upscaling</span> · <span class="link-upcoming">Part 5: Shipping to Kubernetes</span>. More on the <a href="/page/neuroclip/">Neuroclip product page</a>. Neuroclip is in <strong>early access</strong> and a <strong>single-user beta</strong>, so everything below describes what runs on my machine today.</p>
</blockquote>
<aside class="tldr" aria-label="Key takeaways">
<p class="tldr-title">TL;DR</p>
<ul>
<li>Since OBS 28 the obs-websocket v5 server is built into OBS; the protocol is JSON over WebSocket with envelopes of the form <code>{&quot;op&quot;: &lt;int&gt;, &quot;d&quot;: {...}}</code>.</li>
<li>obs-websocket v5 authentication is <code>base64(sha256(password + salt))</code>, then <code>base64(sha256(secret + challenge))</code>, which Go computes with only <code>crypto/sha256</code> and <code>encoding/base64</code>.</li>
<li>OBS reports audio levels as linear multipliers, and silence arrives as <code>null</code> in JSON, so I convert to dBFS with <code>20 · log10(x)</code> and clamp silence to a floor.</li>
<li>Neuroclip&rsquo;s mute alarm watches the raw input peak, which OBS measures before fader and mute, and fires when a muted microphone has heard sound above the noise floor for a while.</li>
<li>Recording chapters via <code>CreateRecordChapter</code> need OBS 30.2 or newer and Hybrid MP4 recordings.</li>
</ul>

</aside>

<p>The first two parts were about things that happen <em>after</em> a stream: cutting, subtitling, exporting. This part is about the live side, which I call the <strong>Regie</strong> (German for &ldquo;direction&rdquo; or &ldquo;control room&rdquo;). The Regie talks to OBS while the stream is running: it switches scenes, saves replays, sets markers, keeps an eye on encoder health, and (my favourite) warns me when I talk into a muted microphone.</p>
<p>I am deliberately staying on the concept level here. Neuroclip is a commercial product, so you will not get a build plan. What I can give you is the public protocol it builds on, the audio maths that trips people up, and the design reasoning behind the alarm. If you only care about the protocol, jump to <a href="#the-obs-websocket-v5-handshake">the handshake</a>. For the alarm idea, go to <a href="#the-mute-alarm-hearing-speech-through-a-muted-microphone">the mute alarm</a>.</p>
<h2 id="what-the-regie-does">What the Regie does</h2>
<p>The Regie page of the dashboard shows the current scene, stream and recording state, the audio inputs with live level meters, a few health numbers and a list of warnings. From there (or from a hotkey, a phone or a Stream Deck) I can:</p>
<ul>
<li>switch scenes, start and stop stream and recording, save the replay buffer,</li>
<li>mute inputs and set fader volumes,</li>
<li>set a <strong>marker</strong> (a Twitch stream marker while streaming, a chapter in the recording while recording),</li>
<li>trigger <strong>&ldquo;Clip jetzt&rdquo;</strong> (a Twitch clip of the last seconds),</li>
<li>toggle sources in the current scene.</li>
</ul>
<p><img src="/img/neuroclip/regie-1440.jpg" alt="The Regie page of the Neuroclip dashboard with scene buttons, audio level meters, health numbers and a microphone warning"></p>
<p><em>The Regie page. The microphone alarm in this screenshot was staged for the picture. I did not actually talk into a muted mic on stream.</em></p>
<p>The dashboard is React, the server is Go, and all OBS traffic goes through one component on the server that speaks the <a href="https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md" rel="noopener">obs-websocket v5 protocol</a>. Since OBS 28 the WebSocket server is built into OBS itself, so there is nothing to install on the OBS side: <em>Tools › WebSocket Server Settings</em>, enable it, set a password.</p>
<h2 id="the-obs-websocket-v5-handshake">The obs-websocket v5 handshake</h2>
<p>The protocol is JSON over WebSocket (<a href="https://www.rfc-editor.org/rfc/rfc6455" rel="noopener">RFC 6455</a>). Every message is an envelope <code>{&quot;op&quot;: &lt;int&gt;, &quot;d&quot;: {...}}</code>. The opcodes that matter for a simple client:</p>
<table>
	<thead>
			<tr>
					<th>op</th>
					<th>Name</th>
					<th>Direction</th>
					<th>Purpose</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>0</td>
					<td>Hello</td>
					<td>OBS → client</td>
					<td>server version, optional auth challenge</td>
			</tr>
			<tr>
					<td>1</td>
					<td>Identify</td>
					<td>client → OBS</td>
					<td>rpcVersion, auth answer, event subscriptions</td>
			</tr>
			<tr>
					<td>2</td>
					<td>Identified</td>
					<td>OBS → client</td>
					<td>login accepted</td>
			</tr>
			<tr>
					<td>5</td>
					<td>Event</td>
					<td>OBS → client</td>
					<td>something happened</td>
			</tr>
			<tr>
					<td>6</td>
					<td>Request</td>
					<td>client → OBS</td>
					<td>do something or read something</td>
			</tr>
			<tr>
					<td>7</td>
					<td>RequestResponse</td>
					<td>OBS → client</td>
					<td>result, matched by <code>requestId</code></td>
			</tr>
	</tbody>
</table>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="Three phases on the wire: the handshake, request/response pairs, and a separate long-lived connection that only receives the high-volume meter events.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 500" width="720" height="500">
  <defs>
    <marker id="ar-nc3-flow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <rect x="40" y="12" width="200" height="44" rx="9" class="d-box d-b"/>
  <text x="140" y="39" class="d-t d-bold" font-size="14" text-anchor="middle">Server (Go)</text>
  <rect x="480" y="12" width="200" height="44" rx="9" class="d-box d-r"/>
  <text x="580" y="39" class="d-t d-bold" font-size="14" text-anchor="middle">OBS (obs-websocket 5)</text>
  <line x1="140" y1="58" x2="140" y2="488" class="d-divider"/>
  <line x1="580" y1="58" x2="580" y2="488" class="d-divider"/>

  <text x="360" y="82" class="d-m" font-size="12" text-anchor="middle">1 · Handshake</text>
  <line x1="578" y1="106" x2="142" y2="106" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="98" class="d-t" font-size="12" text-anchor="middle">Hello (op 0) · challenge + salt</text>
  <line x1="142" y1="162" x2="578" y2="162" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="130" class="d-t" font-size="12" text-anchor="middle">Identify (op 1) · rpcVersion, authentication,</text>
  <text x="360" y="146" class="d-m" font-size="11" text-anchor="middle">eventSubscriptions</text>
  <line x1="578" y1="196" x2="142" y2="196" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="188" class="d-t" font-size="12" text-anchor="middle">Identified (op 2)</text>

  <line x1="40" y1="212" x2="680" y2="212" class="d-divider"/>
  <text x="360" y="234" class="d-m" font-size="12" text-anchor="middle">2 · Request / response (status poll, button click)</text>
  <line x1="142" y1="262" x2="578" y2="262" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="254" class="d-t" font-size="12" text-anchor="middle">Request (op 6) · GetStats, requestId "7"</text>
  <line x1="578" y1="296" x2="142" y2="296" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="288" class="d-t" font-size="12" text-anchor="middle">RequestResponse (op 7) · requestId "7", result</text>

  <line x1="40" y1="318" x2="680" y2="318" class="d-divider"/>
  <text x="360" y="340" class="d-m" font-size="12" text-anchor="middle">3 · Meter connection (own socket, only while someone listens)</text>
  <line x1="142" y1="368" x2="578" y2="368" class="d-arrow" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="360" class="d-t" font-size="12" text-anchor="middle">Identify · subscribe to InputVolumeMeters</text>
  <line x1="578" y1="400" x2="142" y2="400" class="d-arrow d-dashed" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="392" class="d-t" font-size="12" text-anchor="middle">Event (op 5) · InputVolumeMeters (high volume)</text>
  <line x1="578" y1="426" x2="142" y2="426" class="d-arrow d-dashed" marker-end="url(#ar-nc3-flow)"/>
  <text x="360" y="418" class="d-t" font-size="12" text-anchor="middle">Event (op 5) · InputVolumeMeters …</text>

  <rect x="150" y="446" width="420" height="38" rx="9" class="d-box d-y"/>
  <text x="360" y="462" class="d-t" font-size="12" text-anchor="middle">Server keeps the loudest value per interval</text>
  <text x="360" y="477" class="d-t" font-size="12" text-anchor="middle">and publishes fewer frames to the browser</text>
</svg>

    </div>
    <figcaption class="diagram-caption">Three phases on the wire: the handshake, request/response pairs, and a separate long-lived connection that only receives the high-volume meter events.</figcaption>
</figure>

<h3 id="challenge-response-authentication">Challenge-response authentication</h3>
<p>If a password is set, OBS puts an <code>authentication</code> object with a <code>challenge</code> and a <code>salt</code> into its Hello message. The client proves that it knows the password without sending it, as described in the <a href="https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#creating-an-authentication-string" rel="noopener">protocol document</a>:</p>
<ol>
<li><code>secret = base64( sha256( password + salt ) )</code></li>
<li><code>authentication = base64( sha256( secret + challenge ) )</code></li>
</ol>
<p>SHA-256 is specified in <a href="https://csrc.nist.gov/pubs/fips/180-4/upd1/final" rel="noopener">FIPS 180-4</a>. In Go that is a handful of lines using only the standard library:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="kn">package</span><span class="w"> </span><span class="nx">main</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kn">import</span><span class="w"> </span><span class="p">(</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="s">&#34;crypto/sha256&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="s">&#34;encoding/base64&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="s">&#34;fmt&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">authenticationString</span><span class="p">(</span><span class="nx">password</span><span class="p">,</span><span class="w"> </span><span class="nx">salt</span><span class="p">,</span><span class="w"> </span><span class="nx">challenge</span><span class="w"> </span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">secretSum</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">sha256</span><span class="p">.</span><span class="nf">Sum256</span><span class="p">([]</span><span class="nb">byte</span><span class="p">(</span><span class="nx">password</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nx">salt</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">secret</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">base64</span><span class="p">.</span><span class="nx">StdEncoding</span><span class="p">.</span><span class="nf">EncodeToString</span><span class="p">(</span><span class="nx">secretSum</span><span class="p">[:])</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">answerSum</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">sha256</span><span class="p">.</span><span class="nf">Sum256</span><span class="p">([]</span><span class="nb">byte</span><span class="p">(</span><span class="nx">secret</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nx">challenge</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="nx">base64</span><span class="p">.</span><span class="nx">StdEncoding</span><span class="p">.</span><span class="nf">EncodeToString</span><span class="p">(</span><span class="nx">answerSum</span><span class="p">[:])</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="nf">authenticationString</span><span class="p">(</span><span class="s">&#34;password&#34;</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;salt-from-hello&#34;</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;challenge-from-hello&#34;</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>The rest of the handshake is: read Hello, answer with Identify (including the authentication string only if Hello contained an <code>authentication</code> block), and expect op 2. Two details deserve attention. First, <strong>a missing authentication block means OBS has no password</strong>, which is a legitimate setup on a loopback-only machine. Second, put a timeout on the login so a stuck OBS cannot hang a caller forever; a context-aware WebSocket library such as <a href="https://github.com/coder/websocket" rel="noopener"><code>coder/websocket</code></a> makes that natural.</p>
<h3 id="requests-and-events">Requests and events</h3>
<p>A request is op 6 with a <code>requestType</code>, a <code>requestId</code> and optional <code>requestData</code>. The response (op 7) carries the same id plus a status with a result flag and a comment. Because events can arrive between your request and its answer, a client has to skip everything that is not the matching response. Everything useful (switching a scene, saving the replay buffer, muting an input, creating a recording chapter) is one such request. The full list is in the <a href="https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests" rel="noopener">protocol document</a>.</p>
<h2 id="design-lessons-from-the-live-side">Design lessons from the live side</h2>
<p>A few decisions shaped how the Regie behaves. I describe the ideas and leave out the numbers.</p>
<p><strong>One short-lived session per action.</strong> For &ldquo;click a button&rdquo;, the simplest client dials, logs in, sends its requests and closes again. There is no connection state to get wrong: no reconnect logic, no half-dead sockets after an OBS restart. The price is that polling becomes expensive, because every poll is a fresh connection plus a login plus a batch of requests.</p>
<p><strong>Share status reads.</strong> Once several parts of the product (the dashboard, a phone remote, a warning watcher) all wanted the current status, they multiplied the load on an OBS that was busy encoding a game. The fix is the classic pair: let concurrent callers wait for one in-flight fetch instead of each starting their own, and let results be reused for a short moment. Two things need care. Any action that changes OBS must invalidate what was cached, otherwise the next poll shows stale state. And callers must receive copies, so one consumer modifying its view cannot corrupt another&rsquo;s. I have not published before/after numbers; this was a judgement call, and I have no benchmark to back it.</p>
<p><strong>A persistent connection only for the meters.</strong> The one place that needs a permanent connection is the audio meters. <code>InputVolumeMeters</code> is a <em>high-volume</em> event, which the protocol keeps off by default; you opt in with a bit in the Identify message. That connection exists only while somebody is actually looking at the dashboard, it reconnects after errors, and it tells the UI when the link to OBS is lost. Every subscriber only ever needs the <em>newest</em> frame, so a slow browser must never be able to block the producer or the other subscribers. The stale frame gets dropped and the new one kept. The browser gets the frames over Server-Sent Events, a <a href="https://html.spec.whatwg.org/multipage/server-sent-events.html" rel="noopener">WHATWG standard</a> that fits a one-way stream much better than a second WebSocket.</p>
<p>About the state of this design: a single permanent session with events would be the more elegant end state, and it is still on my roadmap. The current shape is simple and hard to break, and the shared status read exists precisely because of its cost. A stateless design has a price, and polling is where you pay it.</p>
<h2 id="audio-meters-db-linear-and-the-third-number">Audio meters: dB, linear, and the third number</h2>
<p>OBS reports levels as <strong>linear multipliers</strong> instead of decibels. Each input has one array per channel, and each array has three values: <code>[magnitude, peak, input-peak]</code>. Magnitude and peak are measured <em>after</em> the fader and mute; the third value is the peak of the signal <em>before</em> fader and mute. Keep that third value in mind, it is the whole trick of the mute alarm.</p>
<p>Conversion to dBFS is the textbook formula <code>20 · log10(x)</code>, with one pitfall: silence is a multiplier of <code>0</code>, and <code>log10(0)</code> is <code>-Inf</code>. OBS reports <code>-inf</code> for the fader of a silent input, which <strong>JSON cannot carry</strong>, so it arrives as <code>null</code>. The safe approach is to never trust dB values from the wire and always compute from the multiplier, clamping silence to a floor:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="kn">package</span><span class="w"> </span><span class="nx">main</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kn">import</span><span class="w"> </span><span class="p">(</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="s">&#34;fmt&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="s">&#34;math&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">const</span><span class="w"> </span><span class="nx">silentDecibels</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="o">-</span><span class="mf">100.0</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">multiplierToDecibels</span><span class="p">(</span><span class="nx">multiplier</span><span class="w"> </span><span class="kt">float64</span><span class="p">)</span><span class="w"> </span><span class="kt">float64</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="nx">multiplier</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nx">math</span><span class="p">.</span><span class="nf">IsNaN</span><span class="p">(</span><span class="nx">multiplier</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="nx">silentDecibels</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="nx">math</span><span class="p">.</span><span class="nf">Max</span><span class="p">(</span><span class="nx">silentDecibels</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="o">*</span><span class="nx">math</span><span class="p">.</span><span class="nf">Log10</span><span class="p">(</span><span class="nx">multiplier</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="nf">multiplierToDecibels</span><span class="p">(</span><span class="mf">0.01</span><span class="p">))</span><span class="w"> </span><span class="c1">// -40</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="nf">multiplierToDecibels</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span><span class="w">    </span><span class="c1">// -100</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Between two published meter frames, keep the <strong>maximum</strong> per input instead of the average, so a short shout still shows up. And think in dB everywhere: a linear 0.01 is −40 dBFS, while −50 dBFS is about 0.003. People think in dB while the hardware reports linear values, and the classic bug is a threshold that is off by orders of magnitude. Keep every threshold in dBFS and convert exactly once, at the edge.</p>
<h2 id="the-mute-alarm-hearing-speech-through-a-muted-microphone">The mute alarm: hearing speech through a muted microphone</h2>
<p>The failure I wanted to catch is embarrassing and common: you are live, you start talking, and your microphone is muted in OBS. Chat is typing &ldquo;can&rsquo;t hear you&rdquo;, and you cannot read it because you are in the game.</p>
<p>A simple &ldquo;mic is muted&rdquo; alarm is useless, because muting is legitimate for coughing, for a phone call, for an AFK break. Talking into a muted mic is the mistake. The signal that separates the two is the <strong>raw input peak</strong>, the third value above. A muted input has zero output, but OBS still measures what the microphone hears <em>before</em> the mute. If that raw level is clearly above the room noise, somebody is talking.</p>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="The mute alarm as a state machine. Speech is judged over a rolling window, not a single loud frame, and the alarm re-arms itself instead of latching.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 420" width="720" height="420">
  <defs>
    <marker id="ar-nc3-mute" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <rect x="20" y="40" width="150" height="64" rx="9" class="d-box d-g"/>
  <text x="95" y="68" class="d-t d-bold" font-size="14" text-anchor="middle">Live</text>
  <text x="95" y="88" class="d-m" font-size="12" text-anchor="middle">mic not muted</text>

  <rect x="230" y="40" width="150" height="64" rx="9" class="d-box d-b"/>
  <text x="305" y="68" class="d-t d-bold" font-size="14" text-anchor="middle">Muted, quiet</text>
  <text x="305" y="88" class="d-m" font-size="12" text-anchor="middle">mute timer running</text>

  <rect x="460" y="40" width="240" height="64" rx="9" class="d-box d-y"/>
  <text x="580" y="66" class="d-t d-bold" font-size="14" text-anchor="middle">Muted, hears speech</text>
  <text x="580" y="85" class="d-m" font-size="12" text-anchor="middle">raw peak clearly above noise floor</text>
  <text x="580" y="99" class="d-m" font-size="11" text-anchor="middle">(measured before the mute)</text>

  <rect x="460" y="220" width="240" height="64" rx="9" class="d-box d-r"/>
  <text x="580" y="248" class="d-t d-bold" font-size="14" text-anchor="middle">ALARM</text>
  <text x="580" y="268" class="d-m" font-size="12" text-anchor="middle">muted-mic warning</text>

  <line x1="170" y1="62" x2="228" y2="62" class="d-arrow" marker-end="url(#ar-nc3-mute)"/>
  <text x="199" y="54" class="d-m" font-size="11" text-anchor="middle">mute</text>
  <line x1="228" y1="86" x2="172" y2="86" class="d-arrow" marker-end="url(#ar-nc3-mute)"/>
  <text x="199" y="100" class="d-m" font-size="11" text-anchor="middle">unmute</text>

  <line x1="382" y1="62" x2="458" y2="62" class="d-arrow" marker-end="url(#ar-nc3-mute)"/>
  <text x="420" y="54" class="d-m" font-size="11" text-anchor="middle">loud frame</text>
  <line x1="458" y1="86" x2="382" y2="86" class="d-arrow d-dashed" marker-end="url(#ar-nc3-mute)"/>
  <text x="420" y="100" class="d-m" font-size="11" text-anchor="middle">window expires</text>

  <line x1="580" y1="106" x2="580" y2="218" class="d-arrow" marker-end="url(#ar-nc3-mute)"/>
  <text x="590" y="150" class="d-t" font-size="12">muted for a while</text>
  <text x="590" y="166" class="d-t" font-size="12">and recent speech</text>
  <text x="590" y="182" class="d-m" font-size="11">within a rolling window</text>

  <path d="M700 252 C 716 252 716 300 700 300 L 660 300 L 660 286" class="d-arrow d-dashed" fill="none" marker-end="url(#ar-nc3-mute)"/>
  <text x="580" y="316" class="d-m" font-size="12" text-anchor="middle">repeats at an interval while it lasts</text>

  <path d="M460 252 C 300 252 95 252 95 108" class="d-arrow" fill="none" marker-end="url(#ar-nc3-mute)"/>
  <text x="270" y="236" class="d-t" font-size="12" text-anchor="middle">unmute: timers and samples reset</text>

  <rect x="20" y="336" width="680" height="64" rx="9" class="d-box"/>
  <text x="360" y="360" class="d-t d-bold" font-size="13" text-anchor="middle">Silenced by design</text>
  <text x="360" y="380" class="d-m" font-size="12" text-anchor="middle">quiet scenes (AFK, starting) · kill switch · only microphone inputs</text>
</svg>

    </div>
    <figcaption class="diagram-caption">The mute alarm as a state machine. Speech is judged over a rolling window, not a single loud frame, and the alarm re-arms itself instead of latching.</figcaption>
</figure>

<p>In words, the alarm fires when the microphone has been muted for a while <em>and</em> has recently heard a meaningful amount of sound clearly above the noise floor. The warning repeats at a calm interval while the situation lasts, and unmuting clears everything at once.</p>
<h3 id="about-hysteresis-honestly">About hysteresis, honestly</h3>
<p>If you expect a textbook Schmitt trigger (two thresholds, one for entering and one for leaving the alarm state), I have to disappoint you: the alarm has no classic hysteresis band. It uses three other mechanisms to avoid flapping:</p>
<ol>
<li><strong>Durations instead of instantaneous levels.</strong> One loud frame does nothing; sound has to accumulate over a window. A cough or a keyboard clack does not.</li>
<li><strong>A margin above the noise floor.</strong> A muted microphone still hears the room, and the margin keeps fan noise out.</li>
<li><strong>A repeat interval instead of re-triggering.</strong> The warning has an identity, and the watcher stays quiet about it until the interval has passed.</li>
</ol>
<p>A time-integrated rule like this tolerates a signal sitting right at the threshold. A rule that switches on and off based on a single instantaneous level would need real hysteresis, so decide which of the two you are building. Two practical details: cap how much time one frame can be credited with (otherwise a stalled connection followed by one loud frame looks like a minute of speech), and sum durations instead of counting frames so the rule does not depend on the frame rate.</p>
<h3 id="where-the-alarm-must-stay-silent">Where the alarm must stay silent</h3>
<p>An alarm that fires at the wrong moments gets switched off, and then it protects nobody. So it has conditions: it only runs while streaming, it stays quiet in scenes where silence is expected (AFK, starting soon), it only looks at inputs that are actually microphones, and there is a kill switch. The thresholds are configurable and clamped on load, so the rest of the code never has to defend against nonsense values.</p>
<p>The same machinery also implements the plainer cousin, &ldquo;microphone or game sound has been silent for too long&rdquo;, using the post-fader peak and ignoring muted inputs, because muted counts as quiet.</p>
<p>One structural choice made all of this easy to test: a stateful tracker collects facts, a stateless rule judges them. That split is the IOSP principle (integration vs. operation) in practice: you build a facts struct, call the rule, assert on the warnings, and no OBS is needed.</p>
<h2 id="health-markers-and-remote-control">Health, markers and remote control</h2>
<p>The health numbers come from <code>GetStats</code>, which returns counters that grow since OBS started. A counter on its own is useless (&ldquo;37,412 skipped frames&rdquo; since when?), so the useful form is a <strong>share over a recent window</strong>: render lag, encoder lag and network drops as a percentage of frames. Two rules apply to any such counter: do not compute shares from a window that is too short, and treat a counter that goes <em>backwards</em> as an OBS restart that resets your history.</p>
<p>Actions are a small closed set. Hotkeys, the phone and the dashboard all call the same runner, so behaviour cannot drift between them. The marker action has two sinks: a Twitch stream marker while streaming, a chapter via <code>CreateRecordChapter</code> while recording. Chapters need <strong>OBS 30.2 or newer and Hybrid MP4 recordings</strong>, so it pays to translate the cryptic &ldquo;unknown request&rdquo; error into exactly that hint. Markers are also logged, and the post-stream tooling reads them as highlights. That is the bridge to the VOD side covered in <a href="/blog/neuroclip-2-vod-to-short-pipeline/">part 2</a>.</p>
<p>For the phone and a Stream Deck, the main API stays on loopback and a separate, tiny HTTP surface offers just a handful of operations, protected by a long random token. When a token has to travel in a URL, put it in the <strong>fragment</strong>: browsers never send it to the server, so it does not end up in an access log. This is meant for a home LAN; if you expose something like it beyond that, put TLS in front of it.</p>
<p>Finally, everything above costs CPU on the same machine that renders the game and encodes the stream. So while OBS is streaming, the product steps back: its own child processes run at lower priority, meter frames are published less often, and scheduled heavy measurements wait until the stream is over.</p>
<h2 id="pitfalls-i-would-warn-you-about">Pitfalls I would warn you about</h2>
<ol>
<li><strong>dB vs. linear.</strong> Keep thresholds in dBFS, convert at the edge, and remember <code>-inf</code> becomes <code>null</code> in JSON.</li>
<li><strong>Raw vs. post-fader levels.</strong> If you alarm on the post-fader peak of a muted mic, you will never hear anything. The pre-mute value carries the information.</li>
<li><strong>Counters since boot.</strong> <code>GetStats</code> counters need a window and a reset-on-decrease rule.</li>
<li><strong>High-volume events are opt-in for a reason.</strong> They are fine for one meter connection and terrible if every poller subscribes.</li>
<li><strong>Time-based rules need injectable clocks.</strong> That is what makes &ldquo;muted for a while&rdquo; testable in microseconds.</li>
<li><strong>A stateless design has a cost.</strong> It is simple and hard to break, and its polling cost is the reason shared status reads exist.</li>
</ol>
<h2 id="whats-next">What&rsquo;s next</h2>
<p>The Regie is the live half of the product. In <span class="link-upcoming">part 4</span> I go back to post-production and look at the most GPU-hungry stage: upscaling facecam footage, a job that, like everything heavy in the product, should not compete with a running stream. If you want to see the whole thing together, the <a href="/page/neuroclip/">Neuroclip page</a> has the overview; early-access requests go to <a href="mailto:info@noobygames.de">info@noobygames.de</a>.</p>
<p>If you build your own OBS tooling in Go, the best starting point is still the <a href="https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md" rel="noopener">official protocol document</a>, which is precise and short. And for the Go side of things, my posts on <a href="/blog/check-static-linking/">static linking checks</a> and <a href="/blog/go-docker/">Go in Docker</a> cover background for the packaging in <span class="link-upcoming">part 5</span>.</p>
]]></content:encoded></item></channel></rss>