<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Himanshu</title>
    <description>The latest articles on DEV Community by Himanshu (@himanshu8881212).</description>
    <link>https://dev.to/himanshu8881212</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280157%2F98c3dc09-8a34-467c-b677-8c7251b5d540.jpg</url>
      <title>DEV Community: Himanshu</title>
      <link>https://dev.to/himanshu8881212</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshu8881212"/>
    <language>en</language>
    <item>
      <title>Push-to-talk for coding agents on a Mac, with a game controller and on-device speech</title>
      <dc:creator>Himanshu</dc:creator>
      <pubDate>Thu, 03 Dec 2026 09:15:47 +0000</pubDate>
      <link>https://dev.to/himanshu8881212/push-to-talk-for-coding-agents-on-a-mac-with-a-game-controller-and-on-device-speech-20ik</link>
      <guid>https://dev.to/himanshu8881212/push-to-talk-for-coding-agents-on-a-mac-with-a-game-controller-and-on-device-speech-20ik</guid>
      <description>&lt;p&gt;Most of my coding now is a conversation with an agent: Claude Code, Codex, OpenCode or Pi in a terminal. Typing long prompts at midnight got old, so I built &lt;strong&gt;CodePad&lt;/strong&gt;. It's a macOS menu-bar app that turns an Xbox or PlayStation controller into a remote for those agents.&lt;/p&gt;

&lt;p&gt;You hold the left trigger and talk. When you let go, the text appears in the agent. Press A to send. The other buttons are the agent's own commands: switch model, thinking effort, plan mode, resume, interrupt, and switching between terminal tabs.&lt;/p&gt;

&lt;p&gt;It's MIT-licensed: &lt;a href="https://github.com/Himanshu8881212/codepad" rel="noopener noreferrer"&gt;github.com/Himanshu8881212/codepad&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post covers the parts that were interesting to build.&lt;/p&gt;

&lt;h2&gt;
  
  
  Speech-to-text that never leaves the Mac
&lt;/h2&gt;

&lt;p&gt;I didn't want audio going to a server, so recognition runs locally with &lt;a href="https://huggingface.co/FermionResearch/Phonon-2-CoreML" rel="noopener noreferrer"&gt;Phonon-2&lt;/a&gt;, a Core ML port of NVIDIA's Parakeet TDT, on the Apple Neural Engine. A typical sentence takes about 10 ms.&lt;/p&gt;

&lt;p&gt;The audio path is small. &lt;code&gt;AVAudioEngine&lt;/code&gt; taps the mic only while the trigger is held. &lt;code&gt;AVAudioConverter&lt;/code&gt; resamples to 16 kHz mono &lt;code&gt;Float32&lt;/code&gt;, and the samples go into a buffer. When you release the trigger, the buffer goes to the model on one serial queue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inputNode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inFormat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;outputFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forBus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;converter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AVAudioConverter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inFormat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// → 16 kHz mono&lt;/span&gt;
&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;installTap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onBus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bufferSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inFormat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kd"&gt;weak&lt;/span&gt; &lt;span class="kc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="kc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because everything goes through one serial queue, a transcription requested while the model is still loading simply waits its turn. That removes a whole class of "not ready yet" bugs.&lt;/p&gt;

&lt;p&gt;Clips shorter than 0.25 s are dropped before they reach the model. That catches accidental trigger taps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Two Neural Engine gotchas
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. The first load compiles the model.&lt;/strong&gt; The first time a Core ML model meets the Neural Engine on a given Mac, macOS compiles it. For a model this size that takes about a minute. Later launches use the cached result and load quickly. CodePad shows "Preparing voice…" once and explains why, rather than looking frozen.&lt;/p&gt;

&lt;p&gt;The model has several input lengths. CodePad loads the 15-second one up front, which covers nearly every spoken prompt, and loads the longer ones in the background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Transcriber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eagerFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;   &lt;span class="c1"&gt;// utterances up to 15 s ready immediately&lt;/span&gt;
&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backgroundLoad&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;   &lt;span class="c1"&gt;// longer windows load later&lt;/span&gt;
&lt;span class="n"&gt;transcriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="nc"&gt;Transcriber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. The Neural Engine powers down when idle.&lt;/strong&gt; After a quiet spell, the first transcription is noticeably slower because the hardware has to wake up. The fix is cheap: when you &lt;em&gt;press&lt;/em&gt; the trigger, CodePad runs a throwaway transcription of one second of silence. By the time you finish speaking, the Neural Engine is awake.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;warmUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;transcriber&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transcribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;repeating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Typing into the terminal without the clipboard
&lt;/h2&gt;

&lt;p&gt;Pasting would overwrite whatever you had copied, so CodePad types the text instead. It posts keyboard events with the Unicode string attached, 16 UTF-16 units at a time. This works with any keyboard layout, because no key codes are involved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CGEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keyboardEventSource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;virtualKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keyboardSetUnicodeString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stringLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unicodeString&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cghidEventTap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This needs the Accessibility permission, which is the only permission CodePad asks for apart from the microphone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Knowing which agent is in front
&lt;/h2&gt;

&lt;p&gt;Each agent has different commands, so the buttons have to follow whichever agent you're looking at. CodePad checks that the front app is a terminal, then reads the focused window's title through the Accessibility API and matches it against each agent. Switch tabs and the mapping switches with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  One code path for Xbox and PlayStation
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;GameController&lt;/code&gt; framework exposes Xbox, DualSense, DualShock and MFi pads through the same &lt;code&gt;GCExtendedGamepad&lt;/code&gt; layout, so reading input is a single function. The only difference is the button labels in the UI: ✕○□△ for PlayStation, ABXY for Xbox.&lt;/p&gt;

&lt;p&gt;One small touch: controllers switch themselves off after about 15 idle minutes. CodePad sends a 40 ms haptic tick at 20% intensity every few idle minutes. You barely feel it, but the pad counts it as activity and stays connected.&lt;/p&gt;

&lt;h2&gt;
  
  
  A menu-bar panel that sizes itself
&lt;/h2&gt;

&lt;p&gt;This part took more iterations than the speech recognition. &lt;code&gt;NSPopover&lt;/code&gt; re-anchors around its old frame when its content changes size, so the content kept sliding sideways or under the menu bar. I replaced it with a borderless &lt;code&gt;NSPanel&lt;/code&gt; that the app places itself, pinned under the menu-bar icon so it only grows downward.&lt;/p&gt;

&lt;p&gt;Inside the panel, a custom SwiftUI &lt;code&gt;Layout&lt;/code&gt; sets the width from the widest control that doesn't wrap, and lets text rows wrap within that width. A test lays out the panel in all 576 combinations of its states: paused, permissions, controller, voice state, agent and so on. It fails the build if the width changes between states or anything spills outside the panel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Requires macOS 15 or later on Apple Silicon.&lt;/li&gt;
&lt;li&gt;Download the DMG from &lt;a href="https://github.com/Himanshu8881212/codepad/releases" rel="noopener noreferrer"&gt;Releases&lt;/a&gt;, or build from source with plain &lt;code&gt;swiftc&lt;/code&gt;; there's no Xcode project.&lt;/li&gt;
&lt;li&gt;It isn't notarized yet, so the first launch needs System Settings → Privacy &amp;amp; Security → &lt;strong&gt;Open Anyway&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Issues and PRs are welcome, especially from PlayStation users and anyone running agents I haven't tried yet.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>macos</category>
      <category>ai</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
