<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/assets/atom.xsl" type="text/xsl"?><feed
	xmlns="http://www.w3.org/2005/Atom"
	xmlns:thr="http://purl.org/syndication/thread/1.0"
	xml:lang="en-US"
	><title>Sacha Chua - category - audio</title>
	<subtitle>Emacs, sketches, and life</subtitle>
	<link rel="self" type="application/atom+xml" href="https://sachachua.com/blog/category/audio/feed/atom/index.xml" />
  <link rel="alternate" type="text/html" href="https://sachachua.com/blog/category/audio" />
  <id>https://sachachua.com/blog/category/audio/feed/atom/index.xml</id>
  <generator uri="https://11ty.dev">11ty</generator>
	<updated>2026-10-26T02:11:17Z</updated>
<entry>
		<title type="html">subed.el and quoting snippets of YouTube videos from the auto captions</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/10/subed-el-and-quoting-snippets-of-youtube-videos-from-the-auto-captions/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-10-26T02:11:17Z</updated>
    <published>2026-10-26T02:11:17Z</published>
    <category term="emacs" />
<category term="audio" />
<category term="subed" />
		<id>https://sachachua.com/blog/2026/10/subed-el-and-quoting-snippets-of-youtube-videos-from-the-auto-captions/</id>
		<content type="html"><![CDATA[<p>
I'm preparing for a conversation with <a href="https://linkarzu.com/">linkarzu</a>.
It would be fun to quote snippets from some of the other videos he has.
I like the way he does a lot of reaction videos that build on what people have shared.
He tends to listen to things at 1.25 or 1.5x speed.
I'm not sure if I have the patience even for that,
so it'd be nice to be able to just quickly skim the text.
He also clips a lot of his own videos.
It might be interesting to play around with my workflows for listening to snippets and clipping them.
</p>

<p>
I've grabbed YouTube captions and reformatted them before:
</p>
<ul class="org-ul">
<li><a href="https://sachachua.com/blog/2021/04/grabbing-the-youtube-auto-generated-captions-is-pretty-useful-when-making-emacs-news/">Grabbing the Youtube auto-generated captions is pretty useful when making Emacs News</a> (2021)</li>
<li><a href="https://sachachua.com/blog/2021/04/org-mode-insert-youtube-video-with-separate-captions/">Org Mode: Insert YouTube video with separate captions</a> (2021)</li>
</ul>

<p>
This time around, I want to get the VTT format so that I can possibly use them with <a href="https://github.com/sachac/subed-record">subed-record</a> to clip audio or video.
</p>

<p>
From a YouTube link, I want to run a single command that gets me a VTT file with that as the media source and with the captions.
If there are any chapters in the description, it would be lovely to get them too. I can get them from the JSON, yay!
</p>

<p>
Now I can use <code>M-x sacha-subed-youtube</code> to open the VTT file, which is cached locally, and I can use <code>M-x sacha-subed-youtube-region-as-quote</code> after selecting a section. Well, actually, I have an Embark command <code>s</code> (for "subed") that I can run on a YouTube video link and a selected-mode shortcut for <code>y</code> that I can run when the region is selected. Results:
</p>

<p>
<a href="https://youtu.be/-1qS7Xiuh9E?t=586&end=619">I Asked Prot If I Should Switch to Emacs</a>
</p>
<blockquote>
<p>
<span class="media-time" data-start="586.000">00:09:46</span>: I think the value of Org is that it is in the context of Emacs, which can now do other things. It can be your email client. It can be your agenda. Of course, it can be your programming environment. All these sorts of things, like your RSS feed reader and so on. And in the context of all that, you also have Org. So for me, that's kind of the value. But otherwise, having Org elsewhere, it's great still, because the paradigm of Org, I think, is a portable paradigm.
</p>
</blockquote>

<p>
<a href="https://youtu.be/N95_UgZXPms?t=0&end=7">Org Mode in Neovim Is Finally Here - Full org.nvim Demo</a>
</p>
<blockquote>
<p>
<span class="media-time" data-start="0.000">00:00:00</span>: I think that I achieved like 100% of parity with the original Org Mode version on Emacs.
</p>
</blockquote>

<details><summary>Code for subed + YouTube</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-subed-youtube-dir</span> <span class="org-string">"~/proj/youtube-captions"</span>
  <span class="org-doc">"Directory with YouTube captions."</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-subed-youtube-temp-dir</span> <span class="org-string">"~/Downloads"</span> <span class="org-doc">"Snap installations need a workaround for permission."</span>)
<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-subed-youtube</span> (url)
  <span class="org-doc">"Download the automatic subtitles or check my cache."</span>
  (<span class="org-keyword">interactive</span> <span class="org-string">"MURL: "</span>)
  (<span class="org-keyword">let*</span> ((id (sacha-org-yt-id url))
         (existing (car (directory-files sacha-subed-youtube-dir t
                                         (concat <span class="org-string">"^"</span> (regexp-quote id) <span class="org-string">".*\\.vtt\\'"</span>)))))
    (<span class="org-keyword">if</span> existing
        (<span class="org-keyword">progn</span>
          (find-file existing)
          (subed-mpv-play-from-url url))
      <span class="org-comment-delimiter">;; </span><span class="org-comment">Download</span>
      (<span class="org-keyword">let</span> ((directory (make-temp-file (expand-file-name <span class="org-string">"yt-dlp"</span> sacha-subed-youtube-temp-dir) t))
            filename
            json
            match
            chapters
            subtitles)
        (<span class="org-keyword">with-current-buffer</span> (get-buffer-create <span class="org-string">"*yt-dlp*"</span>)
          (<span class="org-keyword">let</span> ((default-directory directory))
            (call-process
             <span class="org-string">"yt-dlp"</span> nil t nil
             <span class="org-string">"&#45;&#45;skip-download"</span>
             <span class="org-string">"&#45;&#45;write-info-json"</span>
             <span class="org-string">"&#45;&#45;sub-format"</span>
             <span class="org-string">"vtt"</span>
             <span class="org-string">"&#45;&#45;write-subs"</span>
             <span class="org-string">"&#45;&#45;write-auto-subs"</span>
             url)))
        (<span class="org-keyword">when</span> (null (directory-files directory t <span class="org-string">"\\.json$"</span>))
          (<span class="org-warning">error</span> <span class="org-string">"Could not get data."</span>))
        (<span class="org-keyword">setq</span> json (json-read-file (car (directory-files directory t <span class="org-string">"\\.json$"</span>))))
        (<span class="org-keyword">setq</span> chapters (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">chapters</span> json))
        (<span class="org-keyword">setq</span> filename (expand-file-name
                        (concat id <span class="org-string">" - "</span> (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">title</span> json) <span class="org-string">".vtt"</span>)
                        sacha-subed-youtube-dir))
        (<span class="org-keyword">setq</span> subtitles (subed-parse-file (car (directory-files
                                                directory t
                                                <span class="org-string">"\\.vtt$"</span>))))
        (delete-directory directory t)
        <span class="org-comment-delimiter">;; </span><span class="org-comment">add the chapters as comments</span>
        (mapc
         (<span class="org-keyword">lambda</span> (sub)
           (<span class="org-keyword">when</span> (<span class="org-keyword">and</span> chapters
                      (&gt;= (elt sub 1)
                          (* (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start_time</span> (car chapters)) 1000)))
             (<span class="org-keyword">setf</span> (elt sub 4) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">title</span> (<span class="org-keyword">pop</span> chapters)))))
         subtitles)
        (subed-create-file
         filename
         subtitles
         t)
        (find-file filename)
        (subed-mpv-play-from-url url)))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-subed-youtube-id</span> ()
  <span class="org-doc">"Return the YouTube ID."</span>
  (<span class="org-keyword">or</span> (<span class="org-keyword">save-restriction</span>
        (<span class="org-keyword">save-excursion</span>
          (goto-char (point-min))
          (subed-forward-subtitle-text)
          (<span class="org-keyword">when</span> (subed-record-get-directive <span class="org-string">"YOUTUBE_URL"</span>)
            (sacha-org-yt-id
             (subed-record-get-directive <span class="org-string">"YOUTUBE_URL"</span>)))))
      (car (split-string (file-name-base (buffer-file-name)) <span class="org-string">" "</span>))))

<span class="org-comment-delimiter">;; </span><span class="org-comment">Now we just need a quick way to copy a YouTube URL.</span>
<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-subed-youtube-url</span> (<span class="org-type">&amp;optional</span> start-msecs end-msecs)
  <span class="org-doc">"Copy YouTube URL for the current timestamp."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">when-let*</span>
      ((id (sacha-subed-youtube-id))
       (s
        (<span class="org-keyword">if</span> end-msecs
            (format <span class="org-string">"https://youtu.be/%s?t=%d&amp;end=%d"</span>
                    id
                    (/ (<span class="org-keyword">or</span> start-msecs (subed-subtitle-msecs-start))
                       1000)
                    (1+ (/ end-msecs
                           1000)))
          (format <span class="org-string">"https://youtu.be/%s?t=%d"</span>
                    id
                    (/ (<span class="org-keyword">or</span> start-msecs (subed-subtitle-msecs-start))
                       1000)))))
    (<span class="org-keyword">when</span> (called-interactively-p <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">any</span>)
      (kill-new s)
      (message <span class="org-string">"%s"</span> s))
    s))

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-subed-youtube-play</span> ()
  <span class="org-doc">"Play this video from YouTube."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">when-let*</span>
      ((id (sacha-subed-youtube-id))
       (s (concat <span class="org-string">"https://youtu.be/"</span> id)))
    (<span class="org-keyword">when</span> (string= subed-mpv-media-file s)
      (subed-mpv-play-from-url s))
    (subed-mpv-jump-to-current-subtitle)
    (subed-mpv-unpause)))

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-subed-youtube-region-as-quote</span> (beg end <span class="org-type">&amp;optional</span> label)
  <span class="org-doc">"Format this as a quote."</span>
  (<span class="org-keyword">interactive</span> (list (region-beginning) (region-end) (<span class="org-keyword">when</span> current-prefix-arg (read-string <span class="org-string">"Label: "</span>))))
  (<span class="org-keyword">let*</span> ((id (sacha-subed-youtube-id))
         (url (sacha-subed-youtube-url
               (<span class="org-keyword">save-excursion</span>
                 (goto-char beg)
                 (subed-subtitle-msecs-start))
               (<span class="org-keyword">save-excursion</span>
                 (goto-char end)
                 (subed-subtitle-msecs-stop))))
         (base (file-name-base (buffer-file-name)))
         (text (subed-subtitle-list-text (subed-subtitle-list beg end)))
         (s (format
             <span class="org-string">"%s\n#+begin_quote\n%s: %s\n#+end_quote\n"</span>
             (org-link-make-string
              (concat <span class="org-string">"yt:"</span> url)
              (<span class="org-keyword">or</span> label
                  (<span class="org-keyword">and</span> (string-match (format <span class="org-string">"^%s - </span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(</span></span><span class="org-string">.+</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string">"</span> (regexp-quote id)) base)
                       (match-string 1 base))
                  (sacha-page-title url)))
             (org-link-make-string
              (concat <span class="org-string">"vtime:"</span>
                      (subed-msecs-to-timestamp
                       (<span class="org-keyword">save-excursion</span>
                         (goto-char beg)
                         (subed-subtitle-msecs-start))
                       t)))
             (<span class="org-keyword">with-temp-buffer</span>
               (insert text)
               (<span class="org-keyword">let</span> ((fill-column most-positive-fixnum))
                 (fill-region (point-min) (point-max))
                 (string-trim (buffer-string)))))))
      (<span class="org-keyword">when</span> (called-interactively-p <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">any</span>)
        (kill-new s)
        (message <span class="org-string">"%s"</span> s))
      s))
</code></pre>
</div>

</details>

<p>
Some of this code hasn't been committed to <a href="https://github.com/sachac/subed">subed</a> yet, but I will commit it sometime this week.
</p>

<p>
My next steps might be to:
</p>

<ul class="org-ul">
<li>cache the video as a whole to make it easier to check the waveforms</li>
<li>extract the segment to a standalone video file so that it's easy for me to play back or include in another video</li>
<li>see if I can use my voice activity detection and semi-streaming speech recognition to get a VTT of my current OBS recording</li>
</ul>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#subed">EmacsConfiguration.</a></div><div><a href="https://sachachua.com/blog/2026/10/subed-el-and-quoting-snippets-of-youtube-videos-from-the-auto-captions/index.org">View Org source for this post</a></div><p>You can <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F10%2Fsubed-el-and-quoting-snippets-of-youtube-videos-from-the-auto-captions%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Using Emacs to visualize speaking and target words/phrases in real-ish time</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-10-07T11:47:04Z</updated>
    <published>2026-10-07T11:47:04Z</published>
    <category term="audio" />
<category term="speech-recognition" />
<category term="emacs" />
<category term="learning" />
<category term="visualization" />
		<id>https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/</id>
		<content type="html"><![CDATA[<div class="sticky-toc" id="org60bfade">
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="https://sachachua.com/blog/feed/atom/index.xml#writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-voice-activity-detection-and-speech-recognition">1. Voice activity detection and speech recognition</a></li>
<li><a href="https://sachachua.com/blog/feed/atom/index.xml#writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-noticing-bingo-phrases">2. Noticing bingo phrases</a></li>
</ul>
</div>

</div>


<figure id="org4276db7">
<img src="https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/2026-10-07_07-33-03.png" alt="2026-10-07_07-33-03.png">

<figcaption><span class="figure-number">Figure 1: </span>Screenshot showing my list of target phrases and which ones have been recognized</figcaption>
</figure>

<p>
When I'm working with a tutor to improve my French, I sometimes need
to push myself to provide more details when I'm sharing and ask more
follow-up questions in response to what they're saying, instead of
falling back to « D'accord » and « C'est cool. » Visualizing the
timeline in real-time lets me see if the turn-taking looks good. I
might even need to take a more active role in controlling the
conversation if I happen to be meeting a tutor who tends to go on
monologues.
</p>

<p>
When I'm talking out loud on my own for practice, this might also
nudge me to reduce the pauses and enrich my vocabulary by practising
saying things often enough that they become more automatic.
</p>
<div id="outline-container-writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-voice-activity-detection-and-speech-recognition" class="outline-3">
<h3 id="writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-voice-activity-detection-and-speech-recognition"><span class="section-number-3">1.</span> <a href="https://sachachua.com/blog/feed/atom/index.xml#writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-voice-activity-detection-and-speech-recognition">Voice activity detection and speech recognition</a></h3>
<div class="outline-text-3" id="text-writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-voice-activity-detection-and-speech-recognition">
<p>
This code uses this server <a href="https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/asr.py">vad-file.py</a>, which I generated with Google Gemini. It emits JSONL for voice activity detection events (start/stop) and uses Orukeet to transcribe the speech once the voice activity detection notices it's finished. I also use spacy to look up token information because I want to someday colour the nouns by gender, which might allow me to correct myself in the next sentence instead of hesitating in the previous one.
</p>

<details><summary>code for sacha-vad-tutor</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><code><span class="org-comment-delimiter">;; </span><span class="org-comment">Report on the balance between my tutor and me</span>
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-process</span> nil)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-dir</span> <span class="org-string">"~/vendor/orukeet"</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-command</span> <span class="org-highlight-quoted-quote">`</span>(,(expand-file-name <span class="org-string">".venv/bin/python"</span> sacha-vad-tutor-dir)
                                  <span class="org-string">"asr.py"</span>
                                  <span class="org-string">"&#45;&#45;spacy-model"</span>
                                  <span class="org-string">"fr_dep_news_trf"</span>
                                  <span class="org-string">"-s"</span> <span class="org-string">"300"</span> <span class="org-string">"-t"</span>
                                  <span class="org-string">"VirtualMicSink.monitor=sacha"</span> <span class="org-string">"alsa_output.usb-AT_AT2040USB_202011110001-00.analog-stereo.monitor=other"</span>))
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-events</span> nil <span class="org-doc">"List of events as an list of alists (label start stop duration)."</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-labels</span> <span class="org-highlight-quoted-quote">'</span>(<span class="org-string">"sacha"</span> <span class="org-string">"other"</span>))
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-summary</span> <span class="org-highlight-quoted-quote">'</span>((<span class="org-string">"sacha"</span> . 0)
                                  (<span class="org-string">"other"</span> . 0)))
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-session-length</span> (* 60 60) <span class="org-doc">"Number of seconds to use for scale."</span>)

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-update-view</span> ()
  <span class="org-doc">"Visualize the last 3 minutes and the overview of the session.</span>
<span class="org-doc">Also keep track of target phrases."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">with-current-buffer</span> (get-buffer-create <span class="org-string">"*tutor stats*"</span>)
    (erase-buffer)
    (<span class="org-keyword">let*</span> ((total (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">+</span> (mapcar <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">cdr</span> sacha-vad-tutor-summary)))
           (height 30)
           (width (window-width nil t))
           (max-seconds
            (<span class="org-keyword">if</span> sacha-vad-tutor-events
                (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">max</span> (mapcar (<span class="org-keyword">lambda</span> (o) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> o))
                                    sacha-vad-tutor-events))
              0))
           (threshold 180)              <span class="org-comment-delimiter">; </span><span class="org-comment">last three minutes</span>
           (threshold-seconds (- max-seconds threshold))
           (recent
            (seq-keep
             (<span class="org-keyword">lambda</span> (o)
               (<span class="org-keyword">when</span> (&gt;= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start</span> o)
                         threshold-seconds)
                 (<span class="org-keyword">let-alist</span> o
                   <span class="org-highlight-quoted-quote">`</span>((label . ,.label)
                     (start . ,(- .start threshold-seconds))
                     (end . ,(- .end threshold-seconds))))))
             (copy-sequence sacha-vad-tutor-events)))
           (recent-total (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">+</span> (mapcar (<span class="org-keyword">lambda</span> (o)
                                             (-
                                              (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> o)
                                              (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start</span> o)))
                                           recent))))
      (<span class="org-keyword">save-excursion</span>
        (insert
         (format <span class="org-string">"Last %d minute%s:\n"</span>
                 (/ threshold 60)
                 (<span class="org-keyword">if</span> (&gt; (/ threshold 60) 1)
                     <span class="org-string">"s"</span>
                   <span class="org-string">""</span>))
         (mapconcat
          (<span class="org-keyword">lambda</span> (o)
            (format <span class="org-string">"%d%% %s\n"</span>
                    (/ (* 100.0 (cdr o)) recent-total)
                    (car o)))
          (seq-map
           (<span class="org-keyword">lambda</span> (group)
             (cons (car group)
                   (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">+</span> (mapcar (<span class="org-keyword">lambda</span> (o)
                                       (-
                                        (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> o)
                                        (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start</span> o)))
                                     (cdr group)))))
           (seq-group-by (<span class="org-keyword">lambda</span> (o) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> o)) recent)))
         <span class="org-string">"\n"</span>)
        (svg-insert-image
         (sacha-vad-visualize
          sacha-vad-tutor-labels
          recent
          t
          width height))
        (insert
         <span class="org-string">"\nTotal:\n"</span>

         (mapconcat
          (<span class="org-keyword">lambda</span> (o)
            (format <span class="org-string">"%d%% %s\n"</span>
                    (/ (* 100.0 (cdr o)) total)
                    (car o)))
          sacha-vad-tutor-summary))
        (svg-insert-image
         (sacha-vad-visualize sacha-vad-tutor-labels sacha-vad-tutor-events t
                              width height
                              sacha-vad-tutor-session-length))
        (insert <span class="org-string">"\n\n"</span>  (sacha-learn-lang-bingo-summary))))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-handle-end-event</span> (data)
  <span class="org-doc">"Handle the end event."</span>
  (<span class="org-keyword">let</span> ((event (list
                (cons <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data))
                (cons <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start</span> (- (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">timestamp</span> data)
                                (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">duration</span> data)
                                (<span class="org-keyword">or</span> sacha-vad-tutor-start-seconds 0)))
                (cons <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> (- (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">timestamp</span> data)
                              (<span class="org-keyword">or</span> sacha-vad-tutor-start-seconds 0))))))
    (<span class="org-keyword">push</span> event sacha-vad-tutor-events)
    (<span class="org-keyword">let-alist</span> data
      (<span class="org-keyword">incf</span> (alist-get (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data) sacha-vad-tutor-summary 0 nil <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">string=</span>)
            .duration))
    (sacha-vad-tutor-update-view)))

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-event-handler-functions</span> <span class="org-highlight-quoted-quote">'</span>(sacha-vad-speech-process) <span class="org-doc">"Functions to call with the VAD/transcription events."</span>)

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-process-my-speech</span> nil <span class="org-doc">"Non-nil means process my speech through the whisper setup."</span>)
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-speech-process</span> (data)
  <span class="org-doc">"Process DATA through my whisper input process if it's my speech.</span>
<span class="org-doc">Add to `</span><span class="org-doc"><span class="org-constant">sacha-vad-event-handler-functions</span></span><span class="org-doc">'."</span>
  (<span class="org-keyword">when</span> (<span class="org-keyword">and</span> sacha-vad-process-my-speech
             (string= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">event</span> data) <span class="org-string">"final"</span>)
             (string= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data) sacha-vad-my-label))
    (<span class="org-keyword">with-current-buffer</span> (get-buffer-create whisper&#45;&#45;stdout-buffer-name)
      (erase-buffer)
      (insert (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">text</span> data))
      (goto-char (point-min)))
    (whisper&#45;&#45;handle-transcription-output nil (get-buffer-create whisper&#45;&#45;stdout-buffer-name))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-filter</span> (proc string)
  <span class="org-doc">"Add and parse."</span>
  (<span class="org-keyword">when</span> (buffer-live-p (process-buffer proc))
    <span class="org-comment-delimiter">;; </span><span class="org-comment">split the string by newline?</span>
    (<span class="org-keyword">let</span> ((data (<span class="org-keyword">with-current-buffer</span> (process-buffer proc)
                  (goto-char (point-max))
                  (<span class="org-keyword">save-excursion</span>
                    (insert string))
                  (<span class="org-keyword">catch</span> <span class="org-highlight-quoted-quote">'</span><span class="org-constant">waiting</span>
                    (<span class="org-keyword">unless</span> (<span class="org-keyword">or</span> (eobp) (looking-at <span class="org-string">"\n*$"</span>))
                      (json-read))))))
      (run-hook-with-args <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">sacha-vad-event-handler-functions</span> data)
      (<span class="org-keyword">when</span> (string= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">event</span> data) <span class="org-string">"end"</span>)
        (sacha-vad-handle-end-event data))
      (<span class="org-keyword">when</span> (string= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">event</span> data) <span class="org-string">"final"</span>)
        (sacha-vad-handle-text-event data)))))

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-last-speaker</span> nil <span class="org-doc">"Previous speaker."</span>)

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-transcript-buffer</span> nil <span class="org-doc">"If non-nil, add speech to this buffer."</span>)
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-add-to-transcript</span> (text)
  <span class="org-doc">"Add TEXT to the transcript buffer."</span>
  (<span class="org-keyword">when</span> sacha-vad-transcript-buffer
    (<span class="org-keyword">with-current-buffer</span> (get-buffer-create sacha-vad-transcript-buffer)
      (set (make-local-variable <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">window-point-insertion-type</span>) t)
      (<span class="org-keyword">save-excursion</span>
        (goto-char (point-max))
        (insert text)))))

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-my-label</span> <span class="org-string">"sacha"</span>)
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-handle-text-event</span> (data)
  (sacha-vad-add-to-transcript
   (concat
    (<span class="org-keyword">if</span> (string= sacha-vad-last-speaker (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data))
        <span class="org-string">" "</span>
      (concat (<span class="org-keyword">if</span> (bobp) <span class="org-string">""</span> <span class="org-string">"\n\n"</span>) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data) <span class="org-string">": "</span>))
    (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">text</span> data)))
  (<span class="org-keyword">setq</span> sacha-vad-last-speaker (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data))
  (<span class="org-keyword">when</span> (string= (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> data) sacha-vad-my-label)
    (sacha-learn-lang-notice-bingo-words (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">text</span> data))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-start</span> ()
  <span class="org-doc">"Start the process."</span>
  (<span class="org-keyword">interactive</span>)
  (sacha-vad-tutor-ensure)
  (<span class="org-keyword">setq</span> sacha-vad-tutor-summary <span class="org-highlight-quoted-quote">'</span>((<span class="org-string">"sacha"</span> . 0)
                                  (<span class="org-string">"other"</span> . 0))
        sacha-vad-tutor-events nil)
  (<span class="org-keyword">with-current-buffer</span> (get-buffer-create <span class="org-string">"*Transcript*"</span>)
    (erase-buffer)
    (display-buffer (current-buffer)))
  (display-buffer (get-buffer-create <span class="org-string">"*tutor stats*"</span>)))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-ensure</span> ()
  <span class="org-doc">"Start the process if it's not already running."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">unless</span> (process-live-p sacha-vad-tutor-process)
    (<span class="org-keyword">setq</span> sacha-vad-tutor-process-start-time (current-time))
    (<span class="org-keyword">setq</span> sacha-vad-tutor-start-seconds 0)
    (<span class="org-keyword">let</span> ((default-directory sacha-vad-tutor-dir))
      (<span class="org-keyword">setq</span> sacha-vad-tutor-process
            (make-process
             <span class="org-builtin">:name</span> <span class="org-string">"vad-tutor"</span>
             <span class="org-builtin">:command</span> sacha-vad-tutor-command
             <span class="org-builtin">:connection-type</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">pipe</span>
             <span class="org-builtin">:buffer</span> (get-buffer-create <span class="org-string">"*vad-tutor*"</span>)
             <span class="org-builtin">:stderr</span> (get-buffer-create <span class="org-string">"*vad-tutor-err*"</span>)
             <span class="org-builtin">:filter</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">sacha-vad-tutor-filter</span>)))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-stop</span> ()
  <span class="org-doc">"Stop the process."</span>
  (<span class="org-keyword">interactive</span>)
  (interrupt-process sacha-vad-tutor-process))

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-js-parse-jsonl-file</span> (file)
  <span class="org-doc">"Parse jsonl as a list"</span>
  (<span class="org-keyword">let</span> (results)
    (<span class="org-keyword">with-temp-buffer</span>
      (insert-file-contents file)
      (goto-char (point-min))
      (<span class="org-keyword">while</span> (not (eobp))
        (<span class="org-keyword">condition-case</span> nil
            (<span class="org-keyword">push</span> (json-read) results)
          (<span class="org-warning">error</span> (goto-char (point-max))))))
    (nreverse results)))

(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-start-seconds</span> 0 <span class="org-doc">"Number of seconds to consider as the start."</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-vad-tutor-process-start-time</span> nil <span class="org-doc">"Time that the process started."</span>)

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-reset-clock</span> ()
  <span class="org-doc">"Reset the start of the session."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">setq</span> sacha-vad-tutor-start-seconds
        (time-to-seconds (time-subtract (current-time)
                                        sacha-vad-tutor-process-start-time)))
  (mapcar (<span class="org-keyword">lambda</span> (o) (setcdr o 0)) sacha-vad-tutor-summary)
  (<span class="org-keyword">setq</span> sacha-vad-tutor-events nil))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-visualize</span> (labels list <span class="org-type">&amp;optional</span> output-file width height max-seconds)
  (<span class="org-keyword">setq</span> height (<span class="org-keyword">or</span> height 25))
  (<span class="org-keyword">setq</span> width (<span class="org-keyword">or</span> width (window-width nil t)))
  (<span class="org-keyword">let*</span> ((svg (svg-create width height))
         (max-seconds (max
                       (<span class="org-keyword">or</span> max-seconds 0)
                       (<span class="org-keyword">if</span> list
                           (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">max</span> (mapcar (<span class="org-keyword">lambda</span> (o) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> o))
                                               list))
                         0)))
         (pixels-per-second (/ (* 1.0 width) max-seconds))
         (row-height (/ height (length labels))))
    (<span class="org-keyword">dolist</span> (o list)
      (<span class="org-keyword">let-alist</span> o
        (<span class="org-keyword">let</span> ((y (* row-height (<span class="org-keyword">or</span> (seq-position labels .label <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">string=</span>) -1))))
          (<span class="org-keyword">when</span> (&gt;= y 0)
            (svg-rectangle
             svg
             (* .start pixels-per-second)
             y
             (* (- .end .start) pixels-per-second)
             row-height <span class="org-builtin">:fill</span> <span class="org-string">"green"</span>)))))
    (<span class="org-keyword">cond</span>
     ((stringp output-file)
      (<span class="org-keyword">with-temp-file</span> output-file
        (svg-print svg)))
     (output-file
      svg)
     (t
      (<span class="org-keyword">with-current-buffer</span> (get-buffer-create <span class="org-string">"*vad*"</span>)
        (goto-char (point-min))
        (display-buffer (current-buffer))
        (erase-buffer)
        (svg-insert-image svg))))))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-stats</span> (labels list)
  <span class="org-doc">"Return the balance of time talking as (label total percentage)."</span>
  (<span class="org-keyword">let*</span> ((max-seconds (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">+</span> (mapcar
                                 (<span class="org-keyword">lambda</span> (o) (<span class="org-keyword">let-alist</span> o (- .end .start)))
                                 list)))
         (durations (mapcar (<span class="org-keyword">lambda</span> (o)
                            (cons
                             (car o)
                             (mapcar (<span class="org-keyword">lambda</span> (e) (<span class="org-keyword">let-alist</span> e (- .end .start)))
                                     (cdr o))))
                          (seq-group-by (<span class="org-keyword">lambda</span> (o) (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">label</span> o))
                                        list))))
    (seq-map
     (<span class="org-keyword">lambda</span> (label)
       (<span class="org-keyword">let*</span> ((row (cdr (assoc label durations)))
              (total (apply <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">+</span> row)))
         <span class="org-highlight-quoted-quote">`</span>((label . ,label)
           (total . ,total)
           (count . ,(length row))
           (percentage . ,(<span class="org-keyword">and</span> total max-seconds (&gt; max-seconds 0) (* 100.0 (/ total max-seconds)))))))
     labels)))

<span class="org-comment-delimiter">;; </span><span class="org-comment">(sacha-vad-stats '("sacha" "tutor") (seq-take (sacha-js-parse-jsonl-file "~/proj/speech/output2.log") 5))</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">(sacha-vad-stats '("sacha" "tutor") (sacha-js-parse-jsonl-file "~/proj/speech/output.log"))</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">(sacha-vad-visualize '("sacha" "tutor") (sacha-js-parse-jsonl-file "~/proj/speech/output.log"))</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">(sacha-vad-visualize '("sacha" "tutor") (seq-take (sacha-js-parse-jsonl-file "~/proj/speech/output2.log") 30))</span>

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-group-output</span> (files)
  (<span class="org-keyword">let</span> ((grouped-files (seq-group-by
                        (<span class="org-keyword">lambda</span> (o)
                          (substring (file-name-base o) 0 10))
                        files)))
    (mapcar
     (<span class="org-keyword">lambda</span> (group)
       (<span class="org-keyword">let</span> ((start 0))
         (cons (car (cdr group))
               (seq-reduce
                (<span class="org-keyword">lambda</span> (prev file)
                  (append prev
                          (<span class="org-keyword">let</span> ((max-seconds 0))
                            (<span class="org-keyword">prog1</span> (mapcar (<span class="org-keyword">lambda</span> (event)
                                             (<span class="org-keyword">incf</span> (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">start</span> event) start)
                                             (<span class="org-keyword">incf</span> (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> event) start)
                                             (<span class="org-keyword">setq</span> max-seconds (max (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">end</span> event) max-seconds))
                                             event)
                                           (sacha-js-parse-jsonl-file file))
                              (<span class="org-keyword">setq</span> start max-seconds)))))
                (cdr group)
                nil))))
     grouped-files)))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-vad-tutor-make-table</span> (files <span class="org-type">&amp;optional</span> width height)
  <span class="org-doc">"Make a summary table."</span>
  (<span class="org-keyword">let</span> ((labels sacha-vad-tutor-labels)
        (width (<span class="org-keyword">or</span> width 500))
        (height (<span class="org-keyword">or</span> height 30)))
    <span class="org-comment-delimiter">;; </span><span class="org-comment">combine data as needed</span>
    (append
     <span class="org-highlight-quoted-quote">'</span>((<span class="org-string">"Date"</span> <span class="org-string">"Tutor"</span> <span class="org-string">"Minutes"</span> <span class="org-string">"%"</span> <span class="org-string">"Visualization"</span>) hline)
     (seq-map
      (<span class="org-keyword">lambda</span> (group)
        (<span class="org-keyword">let*</span> ((list (cdr group))
               (base (file-name-base (car group))))
          (<span class="org-keyword">if</span> list
              (<span class="org-keyword">let-alist</span> (car (sacha-vad-stats labels list))
                (<span class="org-keyword">let</span> ((svg-name
                       (expand-file-name
                        (concat (file-name-base (car group)) <span class="org-string">"-"</span> .label <span class="org-string">".svg"</span>)
                        <span class="org-string">"~/proj/french/conversation"</span>)))
                  (sacha-vad-visualize
                   (list .label)
                   list
                   svg-name
                   width
                   height)
                  (list
                   (format-time-string <span class="org-string">"%Y-%m-%d"</span>
                                       (seconds-to-time
                                        (sacha-filename-timestamp (car group))))
                   <span class="org-comment-delimiter">;; </span><span class="org-comment">(org-link-make-string (concat "file:" o) "file")</span>
                   (<span class="org-keyword">if</span> (string-match <span class="org-string">"-conversation-</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(</span></span><span class="org-string">[</span><span class="org-string"><span class="org-negation-char">^</span></span><span class="org-string">\\.]+</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string">"</span> base)
                       (s-capitalize (substring (match-string 1 base) 0 1))
                     <span class="org-string">""</span>)

                   (round (/ .total 60))
                   (format <span class="org-string">"%d%%"</span> .percentage)
                   (org-link-make-string (concat <span class="org-string">"file:"</span> svg-name)
                                         (concat <span class="org-string">"file:"</span> svg-name))
                   )))
            (list <span class="org-string">"?"</span>))))
      (sacha-vad-tutor-group-output files))
     nil)))
</code></pre>
</div>

</details>
</div>
</div>
<div id="outline-container-writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-noticing-bingo-phrases" class="outline-3">
<h3 id="writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-noticing-bingo-phrases"><span class="section-number-3">2.</span> <a href="https://sachachua.com/blog/feed/atom/index.xml#writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-noticing-bingo-phrases">Noticing bingo phrases</a></h3>
<div class="outline-text-3" id="text-writing-and-editing-speech-recognition-using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time-noticing-bingo-phrases">
<p>
Here's the code that reminds me to use the words or expressions on my
to-do list, and then keeps track of how often I've used them,
prioritizes the ones that I haven't used yet, and displays these.
It can work with either my Whisper dictation workflow or the VAD
events server described above.
</p>

<p>
I keep the list of expressions in <a href="https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/bingo.txt">file:///home/sacha/proj/french/bingo.txt</a>.
</p>

<details><summary>Code to notice when I've used an expression</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-learn-lang-bingo-word-file</span> <span class="org-string">"~/proj/french/bingo.txt"</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-learn-lang-bingo-words</span> nil <span class="org-doc">"List of words."</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-learn-lang-bingo-words-hash</span> nil <span class="org-doc">"Data for the counts."</span>)

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-learn-lang-bingo-words</span> ()
  <span class="org-doc">"Load the list of words from the file."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">setq</span> sacha-learn-lang-bingo-words
        (seq-map (<span class="org-keyword">lambda</span> (o)
                   (<span class="org-keyword">when</span> (= (length o) 1)
                     (<span class="org-keyword">setq</span> o (list (car o) 0)))
                   (<span class="org-keyword">setq</span> o (append o (list
                                      (string-trim (replace-regexp-in-string
                                                    <span class="org-string">" *\\[.+?\\] *"</span> <span class="org-string">" "</span>
                                                    (car o))))))
                   o)
                 (pcsv-parse-file sacha-learn-lang-bingo-word-file)))
  sacha-learn-lang-bingo-words)

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-learn-lang-bingo-handler</span> (event)
  <span class="org-doc">"Manually register the event."</span>
  (<span class="org-keyword">interactive</span> <span class="org-string">"e"</span>)
    (<span class="org-keyword">let*</span> ((pos (posn-point (event-end event)))
           (val (get-text-property pos <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">bingo</span>)))
      (<span class="org-keyword">when</span> val
        (sacha-learn-lang-notice-bingo-words val))))

(<span class="org-keyword">defvar-keymap</span> sacha-learn-lang-bingo-map
  <span class="org-string">"&lt;mouse-1&gt;"</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">sacha-learn-lang-bingo-handler</span>)

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-learn-lang-bingo-summary</span> ()
  <span class="org-doc">"Summarize the words to say."</span>
  (<span class="org-keyword">let</span> ((target (seq-filter (<span class="org-keyword">lambda</span> (row) (= (elt row 1) 0))
                            sacha-learn-lang-bingo-words))
        (yay (seq-filter (<span class="org-keyword">lambda</span> (row) (&gt; (elt row 1) 0))
                         sacha-learn-lang-bingo-words)))
    (concat
     (<span class="org-keyword">if</span> target
         (concat <span class="org-string">"Target: "</span>
                 (mapconcat (<span class="org-keyword">lambda</span> (row)
                              (propertize
                               (car row)
                               <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">keymap</span> sacha-learn-lang-bingo-map
                               <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">bingo</span> (car row)))
                            target
                            <span class="org-string">"; "</span>)
                 <span class="org-string">"\n\n"</span>)
       <span class="org-string">""</span>)
     (<span class="org-keyword">if</span> yay
         (concat
          <span class="org-string">"Yay! "</span>
          (mapconcat (<span class="org-keyword">lambda</span> (row)
                       (propertize (format <span class="org-string">"%s (%s)"</span> (car row) (elt row 1))
                                   <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">keymap</span> sacha-learn-lang-bingo-map
                                   <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">bingo</span> (car row)))
                     (seq-filter (<span class="org-keyword">lambda</span> (row) (&gt; (elt row 1) 0))
                                 sacha-learn-lang-bingo-words)
                     <span class="org-string">"; "</span>)
          <span class="org-string">"\n\n"</span>)
       <span class="org-string">""</span>))))

<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-learn-lang-notice-bingo-words</span> (text)
  <span class="org-doc">"Look for the bingo words in TEXT and celebrate when I use them.</span>
<span class="org-doc">Add to `</span><span class="org-doc"><span class="org-constant">whisper-insert-text-at-point</span></span><span class="org-doc">'."</span>
  (<span class="org-keyword">when</span> text
    (<span class="org-keyword">unless</span> sacha-learn-lang-bingo-words (sacha-learn-lang-bingo-words))
    (<span class="org-keyword">let</span> ((found (seq-find
                  (<span class="org-keyword">lambda</span> (o)
                    (<span class="org-keyword">and</span> (elt o 2)
                         (string-match (concat <span class="org-string">"\\&lt;"</span> (elt o 2)) text)))
                  sacha-learn-lang-bingo-words)))
      (<span class="org-keyword">when</span> found
        (<span class="org-keyword">incf</span> (elt found 1))
        (sacha-vad-tutor-update-view)
        (<span class="org-keyword">with-current-buffer</span> (get-buffer-create <span class="org-string">"*Bingo*"</span>)
          (erase-buffer)
          (insert (sacha-learn-lang-bingo-summary))))))
  text)
</code></pre>
</div>

</details>
</div>
</div>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-reporting-speaking-stats-balance">EmacsConfiguration.</a></div><div><a href="https://sachachua.com/blog/2026/10/using-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time/index.org">View Org source for this post</a></div><p>You can <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F10%2Fusing-emacs-to-visualize-speaking-and-target-words-phrases-in-real-ish-time%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Expanding yasnippets by voice in Emacs and other applications</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-03-04T16:17:40Z</updated>
    <published>2026-03-04T16:17:40Z</published>
    <category term="emacs" />
<category term="audio" />
<category term="speech-recognition" />
		<id>https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/</id>
		<content type="html"><![CDATA[<p>
<a href="https://github.com/joaotavora/yasnippet">Yasnippet</a> is a template system for Emacs. I want to use it by voice. I'd like to be able to say things like "Okay, define interactive function" and have that expand to a matching snippet in Emacs or other applications. Here's a quick demonstration of expanding simple snippets:
</p>

<div class="media-post" id="org7591a42">
<p>
</p><figure><video controls="1" src="https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/2026-03-04_12.33.19.webm" type="video/webm"><track kind="subtitles" label="Captions" src="https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/2026-03-04_12.33.19.vtt" srclang="en" default=""><a href="https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/2026-03-04_12.33.19.webm">Download the video</a></video><figcaption><div>Screencast of expanding snippets by voice in Emacs and in other applications</div></figcaption></figure>
<p></p>

<details class="code-details" style="padding: 1em;
                 border-radius: 15px;
                 font-size: 0.9em;
                 box-shadow: 0.05em 0.1em 5px 0.01em  #00000057;">
                  <summary><strong>Transcript</strong></summary>
<ul class="org-ul">
<li><span class="media-time" data-start="0.000">00:00</span> So I've defined some yasnippets with names that I can say. Here, for example, in this menu, you can see I've got "define interactive function" and "with a buffer that I'll display." And in fundamental mode, I have some other things too. Let's give it a try.</li>
<li><span class="media-time" data-start="19.000">00:19</span> I press my shortcut. "Okay, define an interactive function." You can see that this is a yasnippet. Tab navigation still works.</li>
<li><span class="media-time" data-start="33.000">00:33</span> I can say, "OK, with a buffer that I'll display," and it expands that also.</li>
<li><span class="media-time" data-start="45.000">00:45</span> I can expand snippets in other applications as well, thanks to a global keyboard shortcut.</li>
<li><span class="media-time" data-start="50.000">00:50</span> Here, for example, I can say, "OK, my email." It inserts my email address.</li>
<li><span class="media-time" data-start="62.000">01:02</span> Yasnippet definitions can also execute Emacs Lisp. So I can say, "OK, date today," and have that evaluated to the actual date.</li>
<li><span class="media-time" data-start="81.000">01:21</span> So that's an example of using voice to expand snippets.</li>
</ul>


</details>

</div>

<p>
This is handled by the following code:
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-maybe-expand-snippet</span> (text)
  <span class="org-doc">"Add to `</span><span class="org-doc"><span class="org-constant">whisper-insert-text-at-point</span></span><span class="org-doc">'."</span>
  (<span class="org-keyword">if</span> (<span class="org-keyword">and</span> text
           (string-match
            <span class="org-string">"^ok</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(?:</span></span><span class="org-string">ay</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string">?[,\\.]? </span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(</span></span><span class="org-string">.+</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string">"</span> text))
    (<span class="org-keyword">let*</span> ((name
            (downcase
             (string-trim
              (replace-regexp-in-string <span class="org-string">"[,\\.]"</span> <span class="org-string">""</span> (match-string 1 text)))))
           (matching
            (seq-find (<span class="org-keyword">lambda</span> (o)
                        (subed-word-data-compare-normalized-string-distance
                         name
                         (downcase (yas&#45;&#45;template-name o))))
                      (yas&#45;&#45;all-templates (yas&#45;&#45;get-snippet-tables)))))
      (<span class="org-keyword">if</span> matching
          (<span class="org-keyword">progn</span>
            (<span class="org-keyword">if</span> (frame-focus-state)
                (<span class="org-keyword">progn</span>
                  (yas-expand-snippet matching)
                  nil)
              <span class="org-comment-delimiter">;; </span><span class="org-comment">In another application</span>
              (<span class="org-keyword">with-temp-buffer</span>
                (yas-minor-mode)
                (yas-expand-snippet matching)
                (buffer-string))))
        text))
    text))
</code></pre>
</div>


<p>
This code relies on <a href="https://github.com/sachac/whisper.el/">my fork of whisper.el</a>, which lets me specify a list of functions for <code>whisper-insert-text-at-point</code>. (I haven't asked for upstream review yet because I'm still testing things, and I don't know if it actually works for anyone else yet.) It does approximate matching on the snippet name using a function from <a href="https://github.com/sachac/subed/blob/main/subed/subed-word-data.el">subed-word-data.el</a> which just uses <code>string-distance</code>. I could probably duplicate the function in my config, but then I'd have to update it in two places if I come up with more ideas.
</p>

<p>
The code for inserting into other functions is defined in <a href="https://sachachua.com/blog/2026/01/using-whisper-el-to-capture-text-to-speech-in-emacs/#multimedia-whisper">my-whisper-maybe-type</a>, which is very simple:
</p>

<p>

</p><div class="org-src-container">
<pre class="src src-emacs-lisp" id="org3c4a075"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-maybe-type</span> (text)
  <span class="org-doc">"If Emacs is not the focused app, simulate typing TEXT.</span>
<span class="org-doc">Add this function to `</span><span class="org-doc"><span class="org-constant">whisper-insert-text-at-point</span></span><span class="org-doc">'."</span>
  (<span class="org-keyword">when</span> text
    (<span class="org-keyword">if</span> (frame-focus-state)
        text
      (make-process <span class="org-builtin">:name</span> <span class="org-string">"xdotool"</span> <span class="org-builtin">:command</span>
                    (list <span class="org-string">"xdotool"</span> <span class="org-string">"type"</span>
                          text))
      nil)))
</code></pre>
</div>


<p></p>

<p>
Someday I'd like to provide alternative names for snippets. I also want to make it easy to fill in snippet fields by voice. I'd love to be able to answer minibuffer questions from <code>yas-choose-value</code>, <code>yas-completing-read</code>, and other functions by voice too. Could be fun!
</p>

<p>
Related:
</p>

<ul class="org-ul">
<li><a href="https://github.com/sachac/snippets">My snippets repository</a></li>
<li><a href="https://sachachua.com/topic/speech-recognition/">My topic page for speech recognition</a></li>
</ul>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-expanding-yasnippet-by-voice">Emacs configuration.</a></div><div><a href="https://sachachua.com/blog/2026/03/expanding-yasnippet-by-voice/index.org">View Org source for this post</a></div><p>You can <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F03%2Fexpanding-yasnippet-by-voice%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Using speech recognition for on-the-fly translations in Emacs and faking in-buffer completion for the results</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/02/using-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-03-31T16:31:15Z</updated>
    <published>2026-02-27T20:11:58Z</published>
    <category term="audio" />
<category term="speech-recognition" />
<category term="emacs" />
<category term="speech" />
		<id>https://sachachua.com/blog/2026/02/using-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results/</id>
		<content type="html"><![CDATA[<div class="update" id="orgeabb215">
<p>
<span class="timestamp-wrapper"><time class="timestamp" datetime="2026-03-31">[2026-03-31 Tue]</time></span>: I added the recognized text so that I can confirm what was translated. I also moved my-type-with-hint to <a href="https://codeberg.org/sachac/learn-lang/src/branch/main/learn-lang-type.el">learn-lang-type-with-hint</a>.
</p>

</div>

<p>
When I'm writing a journal entry in French, I
sometimes want to translate a phrase that I can't
look up word by word using a dictionary.
Instead of switching to a browser, I can use an
Emacs function to prompt me for text and either
insert or display the translation.
The <a href="https://github.com/alphapapa/plz.el">plz</a> library makes HTTP requests slightly
neater.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">my-lang-en-to-fr</span> (text <span class="org-type">&amp;optional</span> display-only)
  (<span class="org-keyword">interactive</span> (list (read-string <span class="org-string">"Text: "</span>) current-prefix-arg))
  (<span class="org-keyword">let*</span> ((url <span class="org-string">"https://translation.googleapis.com/language/translate/v2"</span>)
         (params <span class="org-highlight-quoted-quote">`</span>((<span class="org-string">"key"</span> . ,(getenv <span class="org-string">"GOOGLE_API_KEY"</span>))
                   (<span class="org-string">"q"</span> . ,text)
                   (<span class="org-string">"source"</span> . <span class="org-string">"en"</span>)
                   (<span class="org-string">"target"</span> . <span class="org-string">"fr"</span>)
                   (<span class="org-string">"format"</span> . <span class="org-string">"text"</span>)))
         (query-string (mapconcat
                        (<span class="org-keyword">lambda</span> (pair)
                          (format <span class="org-string">"%s=%s"</span>
                                  (url-hexify-string (car pair))
                                  (url-hexify-string (cdr pair))))
                        params
                        <span class="org-string">"&amp;"</span>))
         (full-url (concat url <span class="org-string">"?"</span> query-string)))
    (<span class="org-keyword">let*</span> ((response (plz <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">get</span> full-url <span class="org-builtin">:as</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">json-read</span>))
           (data (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">data</span> response))
           (translations (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">translations</span> data))
           (first-translation (car translations))
           (translated-text (alist-get <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">translatedText</span> first-translation)))
      (<span class="org-keyword">when</span> (called-interactively-p <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">any</span>)
        (<span class="org-keyword">if</span> display-only
            (message <span class="org-string">"%s"</span> translated-text)
          (insert translated-text)))
      translated-text)))
</code></pre>
</div>


<p>
I think it would be even nicer if I could use speech synthesis, so I can keep it a little more separate from my typing thoughts. I want to be able to say "Okay, translate &hellip;" or "Okay, &hellip; in French" to get a translation. I've been using <a href="https://github.com/sachac/whisper.el/">my fork of natrys/whisper.el</a> for <a href="https://sachachua.com/topic/speech-recognition/">speech recognition</a> in English, and I like it a lot. By adding a function to <code>whisper-after-transcription-hook</code>, I can modify the intermediate results before they're inserted into the buffer.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-translate</span> ()
  (goto-char (point-min))
  (<span class="org-keyword">let</span> ((case-fold-search t))
    (<span class="org-keyword">when</span> (re-search-forward <span class="org-string">"okay[,\\.]? translate[,\\.]? </span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(</span></span><span class="org-string">.+</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">|</span></span><span class="org-string">okay[,\\.]? </span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">(</span></span><span class="org-string">.+?</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">)</span></span><span class="org-string"> in French"</span> nil t)
      (<span class="org-keyword">let*</span> ((s (<span class="org-keyword">or</span> (match-string 1) (match-string 2)))
             (translation (<span class="org-keyword">save-match-data</span> (my-lang-en-to-fr s))))
        (replace-match
         (propertize translation
                     <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">type-hint</span> translation
                     <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">type-original</span> s
                     <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">help-echo</span> s))))))

(<span class="org-keyword">with-eval-after-load</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper</span>
  (add-hook <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper-after-transcription-hook</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">my-whisper-translate</span> 70))
</code></pre>
</div>


<p>
But that's too easy. I want to actually type things myself so that I get more practice. Something like an autocomplete suggestion would be handy as a way of showing me a hint at the cursor. The usual completion-at-point functions are too eager to insert things if there's only one candidate, so we'll just fake it with an overlay. This code works only with my whisper.el fork because it supports using a list of functions for <code>whisper-insert-text-at-point</code>.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-maybe-type-with-hints</span> (text)
  <span class="org-doc">"Add this function to `</span><span class="org-doc"><span class="org-constant">whisper-insert-text-at-point</span></span><span class="org-doc">'."</span>
  (<span class="org-keyword">let*</span> ((hint (<span class="org-keyword">and</span> text (org-find-text-property-in-string <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">type-hint</span> text)))
         (original (<span class="org-keyword">and</span> text (org-find-text-property-in-string <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">type-original</span> text))))
    (<span class="org-keyword">if</span> hint
        (<span class="org-keyword">progn</span>
          (learn-lang-type-with-hint hint original)
          nil)
      text)))
</code></pre>
</div>


<p>
Here's a demonstration of me saying "Okay, this is a test, in French.":
</p>

<div class="media-post" id="orgdf2cbf2">
<p>
</p><figure><video controls="1" src="https://sachachua.com/blog/2026/02/using-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results/2026-02-27-translate-and-type-with-hints.webm" type="video/webm"><a href="https://sachachua.com/blog/2026/02/using-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results/2026-02-27-translate-and-type-with-hints.webm">Download the video</a></video><figcaption><div>Screencast of using speech recognition to translate into French and provide a hint when typing</div></figcaption></figure>
<p></p>

</div>

<p>
Since we're faking in-buffer completion here, maybe we can still get away with considering this as an entry for <a href="https://sachachua.com/blog/2026/01/emacs-carnival-february-2026-completion/">Emacs Carnival February 2026: Completion</a> ? =)</p>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-using-speech-recognition-for-translations-in-emacs-and-faking-in-buffer-completion-for-the-results">Emacs configuration.</a></div><div><a href="https://sachachua.com/blog/2026/02/using-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results/index.org">View Org source for this post</a></div><p>You can <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F02%2Fusing-speech-recognition-for-on-the-fly-translations-in-emacs-and-faking-in-buffer-completion-for-the-results%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Using Silero voice activity detection to automatically queue multiple transcriptions with natrys/whisper.el</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/01/using-silero-voice-activity-detection-to-automatically-queue-multiple-transcriptions-with-natrys-whisper-el/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-03-27T23:03:01Z</updated>
    <published>2026-01-29T16:24:46Z</published>
    <category term="audio" />
<category term="speech-recognition" />
<category term="emacs" />
		<id>https://sachachua.com/blog/2026/01/using-silero-voice-activity-detection-to-automatically-queue-multiple-transcriptions-with-natrys-whisper-el/</id>
		<content type="html"><![CDATA[<div class="update" id="org67634b7">
<p>
<span class="timestamp-wrapper"><time class="timestamp" datetime="2026-03-27">[2026-03-27 Fri]</time></span>: Moved code to <a href="https://codeberg.org/sachac/speech-input">sachac/speech-input</a>.
</p>

</div>

<p>
I can <a href="https://sachachua.com/blog/2026/01/queue-multiple-transcriptions-with-whisper-el-speech-recognition/">queue multiple transcriptions with whisper.el</a> so that they get processed sequentially with backup audio. It catches up when I pause to think. Now I want to use <a href="https://pytorch.org/hub/snakers4_silero-vad_vad/">Silero voice activity detection</a> to do that kind of segmentation for me automatically.
</p>

<p>
First, I need a Python server that can print out events when it notices the start or stop of a speech segment. If I print out the timestamps, I might be able to cross-reference it someday with interestingthings. For now, even just paying attention to the end of a segment is enough for what I want to do.
</p>

<details class="code-details" style="padding: 1em;
                 border-radius: 15px;
                 font-size: 0.9em;
                 box-shadow: 0.05em 0.1em 5px 0.01em  #00000057;">
                  <summary><strong>Python script for printing out events</strong></summary>

<div class="org-src-container">
<pre class="src src-python"><code><span class="org-keyword">import</span> sounddevice <span class="org-keyword">as</span> sd
<span class="org-keyword">import</span> numpy <span class="org-keyword">as</span> np
<span class="org-keyword">import</span> torch
<span class="org-keyword">import</span> sys
<span class="org-keyword">from</span> datetime <span class="org-keyword">import</span> datetime, timedelta

<span class="org-variable-name">SILENCE_DURATION</span> <span class="org-operator">=</span> 500
<span class="org-variable-name">SAMPLING_RATE</span> <span class="org-operator">=</span> 16000
<span class="org-variable-name">CHUNK_SIZE</span> <span class="org-operator">=</span> 512
<span class="org-variable-name">model</span>, <span class="org-variable-name">utils</span> <span class="org-operator">=</span> torch.hub.load(repo_or_dir<span class="org-operator">=</span><span class="org-string">'snakers4/silero-vad'</span>,
                              model<span class="org-operator">=</span><span class="org-string">'silero_vad'</span>,
                              force_reload<span class="org-operator">=</span><span class="org-constant">False</span>)

(<span class="org-variable-name">get_speech_timestamps</span>, <span class="org-variable-name">save_audio</span>, <span class="org-variable-name">read_audio</span>, <span class="org-variable-name">VADIterator</span>, <span class="org-variable-name">collect_chunks</span>) <span class="org-operator">=</span> utils
<span class="org-variable-name">vad_iterator</span> <span class="org-operator">=</span> VADIterator(model, threshold<span class="org-operator">=</span>0.5, min_silence_duration_ms<span class="org-operator">=</span>SILENCE_DURATION)

<span class="org-variable-name">stream_start_time</span> <span class="org-operator">=</span> <span class="org-constant">None</span>

<span class="org-keyword">def</span> <span class="org-function-name">format_iso_with_offset</span>(offset_seconds):
    <span class="org-keyword">if</span> stream_start_time <span class="org-keyword">is</span> <span class="org-constant">None</span>:
        <span class="org-keyword">return</span> <span class="org-string">"PENDING"</span>
    <span class="org-variable-name">event_time</span> <span class="org-operator">=</span> stream_start_time <span class="org-operator">+</span> timedelta(seconds<span class="org-operator">=</span>offset_seconds)
    <span class="org-keyword">return</span> event_time.astimezone().isoformat(timespec<span class="org-operator">=</span><span class="org-string">'milliseconds'</span>)

<span class="org-keyword">def</span> <span class="org-function-name">audio_callback</span>(indata, frames, time, status):
    <span class="org-keyword">global</span> stream_start_time
    <span class="org-keyword">if</span> status:
        <span class="org-builtin">print</span>(status, file<span class="org-operator">=</span>sys.stderr)
    <span class="org-keyword">if</span> stream_start_time <span class="org-keyword">is</span> <span class="org-constant">None</span>:
        <span class="org-variable-name">stream_start_time</span> <span class="org-operator">=</span> datetime.now()
    <span class="org-variable-name">tensor_input</span> <span class="org-operator">=</span> torch.from_numpy(indata.copy()).flatten()
    <span class="org-variable-name">speech_dict</span> <span class="org-operator">=</span> vad_iterator(tensor_input, return_seconds<span class="org-operator">=</span><span class="org-constant">True</span>)
    <span class="org-keyword">if</span> speech_dict:
        <span class="org-keyword">if</span> <span class="org-string">"start"</span> <span class="org-keyword">in</span> speech_dict:
            <span class="org-builtin">print</span>(f<span class="org-string">"START </span>{format_iso_with_offset(speech_dict['start'])}<span class="org-string">"</span>, flush<span class="org-operator">=</span><span class="org-constant">True</span>)
        <span class="org-keyword">if</span> <span class="org-string">"end"</span> <span class="org-keyword">in</span> speech_dict:
            <span class="org-builtin">print</span>(f<span class="org-string">"END </span>{format_iso_with_offset(speech_dict['end'])}<span class="org-string">"</span>, flush<span class="org-operator">=</span><span class="org-constant">True</span>)
<span class="org-keyword">try</span>:
    <span class="org-keyword">with</span> sd.InputStream(samplerate<span class="org-operator">=</span>SAMPLING_RATE,
                        channels<span class="org-operator">=</span>1,
                        callback<span class="org-operator">=</span>audio_callback,
                        blocksize<span class="org-operator">=</span>CHUNK_SIZE):
        <span class="org-keyword">while</span> <span class="org-constant">True</span>:
            <span class="org-keyword">pass</span>
<span class="org-keyword">except</span> <span class="org-type">KeyboardInterrupt</span>:
    <span class="org-builtin">print</span>(<span class="org-string">"</span><span class="org-constant">\n</span><span class="org-string">Stopping..."</span>)
</code></pre>
</div>



</details>

<p>
I've mode the code to <a href="https://codeberg.org/sachac/speech-input/src/branch/main/speech-input-vad.el">speech-input-vad.el</a>, so now I can use <code>speech-input-vad-start</code> to start monitoring speech events.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">use-package</span> speech-input <span class="org-builtin">:load-path</span> <span class="org-string">"~/proj/speech-input/"</span>)
</code></pre>
</div>


<p>
Because I added Pulse properties to the process environment, I can easily use <a href="https://sachachua.com/blog/2026/01/visualizing-and-managing-pipewire-audio-graphs-from-emacs/">epwgraph</a> to rewire the input so that it gets the input from my VirtualMicSink instead of the default system audio device. (Someday I'll figure out how to specify that as the input automatically.)
</p>

<p>
Then I can start this process from Emacs:
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">with-eval-after-load</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">speech-input-vad</span>
  (add-hook <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">speech-input-vad-on-end-functions</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">my-whisper-maybe-continue</span>))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-maybe-continue</span> ()
  (<span class="org-keyword">when</span> (process-live-p whisper&#45;&#45;recording-process)
    (my-whisper-continue)))
</code></pre>
</div>


<p>
Now I can press my shortcut for <code>my-whisper-continue</code> to start the process. As I keep talking, it will continue to record. When I pause for more than a second between sentences, then it will send that chunk to the server for transcription without me having to press another button, while still listening for more speech.
</p>

<p>
How is this different from the streaming approach that many real-time speech recognition services offer? I think this gives me a bit more visibility into and control of the process. For my personal use, I don't need to have everything processed as quickly as possible, and I'm not trying to replicate live captions. I just want to be able to look back over the last five minutes to try to remember what I was talking about. I usually have a lot of quiet time as I think through my next steps, and it's fine to have it catch up then. I also like that I can save time-stamped audio files for later processing, divided according to the speech segments. Those might be a little bit easier to work with when I get around to compositing them into a video.
</p>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-using-silero-voice-activity-detection-to-automatically-queue-multiple-transcriptions-with-natrys-whisper-el">Emacs configuration.</a></div><div><a href="https://sachachua.com/blog/2026/01/using-silero-voice-activity-detection-to-automatically-queue-multiple-transcriptions-with-natrys-whisper-el/index.org">View Org source for this post</a></div><p>You can <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F01%2Fusing-silero-voice-activity-detection-to-automatically-queue-multiple-transcriptions-with-natrys-whisper-el%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Queuing multiple transcriptions with whisper.el speech recognition</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/01/queue-multiple-transcriptions-with-whisper-el-speech-recognition/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-01-23T19:50:37Z</updated>
    <published>2026-01-23T19:50:37Z</published>
    <category term="audio" />
<category term="speech-recognition" />
<category term="emacs" />
		<id>https://sachachua.com/blog/2026/01/queue-multiple-transcriptions-with-whisper-el-speech-recognition/</id>
		<content type="html"><![CDATA[<p>
I want to be able to talk out loud and have the ideas go into Emacs. I can do this in a number of different ways:
</p>

<ol class="org-ol">
<li>I briefly demonstrated a step-by-step approach with <a href="https://sachachua.com/blog/2026/01/using-whisper-el-to-capture-text-to-speech-in-emacs/">natrys/whisper.el with a single file</a>. I press a keyboard shortcut to start the recording, another shortcut to stop the recording, and it transcribes it in the background. But the way whisper.el is set up is that if I press the keyboard shortcut to start recording again it will offer to interrupt the transcription process, which is not what I want. I want to just keep talking and have it process results as things come in.</li>
<li>I'm also experimenting with <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-streaming-speech-recognition-into-emacs-using-google-chrome-web-speech-api">Google Chrome's web speech API to do continuous speech recognition</a>, which I can get into Emacs using a web socket.</li>
<li>What I've just figured out is how to layer a semi-continuous interface for speech recognition on top of whisper.el so that while it's processing in the background, I can just press a keyboard shortcut (I'm using numpad 9 to call <code>my-whisper-continue</code>) to stop the previous recording, queue it for processing, and start the next recording. If I use this keyboard shortcut to separate my thoughts, then Whisper has a much easier time making sense of the whole sentence or paragraph or whatever, instead of trying to use the sliding 30 second context window that many streaming approaches to speech recognition try to use.</li>
</ol>

<p>
Question: Did you fix the keyboard delay you've got while speech catches what you're saying?
</p>

<p>
Sometimes, when the speed recognition kicks in, my computer gets busy. When my computer gets really busy, it doesn't process my keystrokes in the right order, which is very annoying because then I have to delete the previous word and retype it. I haven't sorted that out yet, but it seems like I probably have to lower the priority on different processes. On the plus side, as I mentioned, if I dictate things instead of typing them, then I don't run into that problem at all.
</p>

<p>
Also, other notes on delays: The continuous speech recognition via Google Chrome shows up fairly quickly, but it's not very precise, and it doesn't have punctuation. Even if there's a little bit of a delay, as long as I press the my-whisper-continue shortcut after each thought, then I can get that text into my Emacs buffer using the nicer transcription from my selected model. There is going to be a bit of a delay for that one because it gets processed at the end of the thought. Also, I need to start thinking in complete sentences instead of just adding one cause after the other as my brain goes on all of these tangents. I think it's pretty promising. There's the continuous speech recognition via Google Chrome if I don't mind the lower accuracy and lack of punctuation, and I can still get the pretty version on the other side.
</p>

<p>
Why talk out loud? I liked the <a href="https://emacsconf.org/2025/talks/bookclub-tapas">Bookclub Tapas</a> presentation that Maddie Sullivan did at EmacsConf 2025. Talking out loud helps me be a lot more verbose about what I'm saying, compared to typing things out or even like having to switch to my notes or interrupting my screen with an Org capture buffer. Of course I want to clean that up for  putting into a blog post, but given that my life still sometimes has random interruptions from a kiddo who must have my attention at that very minute, having that kind of record that I can at least try to reread afterwards to reconstruct what I was thinking about sounds like it might be helpful.
</p>

<p>
Still, making sense out loud is hard. I'm not actually used to talking to people that much now. This is probably a good reason for me to experiment with streaming more. Then I get the practice in talking out loud, there are backup recordings, and people can ask questions when things are unclear.
</p>

<p>
Of course, sometimes the text doesn't quite make sense because of the speech recognition errors. I can usually figure it out from the context. I save the audio as well so that I can go back and listen to it again if I really need to.
</p>

<p>
Anyway, here's the code for sending the current recording to whisper in the background and starting another recording. It assumes a lot about how things are set up. For example, I'm only testing this with a local speaches server instead of whisper.cpp. You might need to look at my other speech related configuration blog posts and sections in order to make sense of it.
</p>

<details><summary>Code for queuing whisper.el requests to a local server</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defvar</span> <span class="org-variable-name">my-whisper&#45;&#45;queue</span> nil)
(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-continue</span> (<span class="org-type">&amp;optional</span> arg)
  <span class="org-doc">"Send what we've got so far for transcription and then continue recording.</span>
<span class="org-doc">Call with \\[</span><span class="org-doc"><span class="org-constant">universal-argument</span></span><span class="org-doc">] to signal that we can stop."</span>
  (<span class="org-keyword">interactive</span> <span class="org-string">"P"</span>)
  (<span class="org-keyword">require</span> <span class="org-highlight-quoted-quote">'</span><span class="org-constant">whisper</span>)
  (<span class="org-keyword">if</span> arg
      (my-whisper-done)
    (<span class="org-keyword">setq</span> whisper&#45;&#45;marker (point-marker) whisper&#45;&#45;point-buffer (current-buffer))
    (<span class="org-keyword">when</span> (process-live-p whisper&#45;&#45;recording-process)
      <span class="org-comment-delimiter">;; </span><span class="org-comment">queue only if the last one is not asking for the same file</span>
      (<span class="org-keyword">unless</span>
          (string=
           (plist-get
            (car
             (last my-whisper&#45;&#45;queue))
            <span class="org-builtin">:file</span>)
           whisper&#45;&#45;temp-file)
        (add-to-list
         <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">my-whisper&#45;&#45;queue</span>
         (list <span class="org-builtin">:file</span> whisper&#45;&#45;temp-file
               <span class="org-builtin">:buffer</span>
               (format <span class="org-string">"*result: %s*"</span> (file-name-base whisper&#45;&#45;temp-file)))
         t))
      <span class="org-comment-delimiter">;; </span><span class="org-comment">Remove the sentinel; handle results ourselves</span>
      (set-process-sentinel whisper&#45;&#45;recording-process
                            (<span class="org-keyword">lambda</span> (process event)
                              (my-whisper-process-queue)))
      (interrupt-process whisper&#45;&#45;recording-process))
    (run-hooks <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper-before-transcription-hook</span>)
    (whisper&#45;&#45;setup-mode-line <span class="org-builtin">:show</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">recording</span>)
    (whisper&#45;&#45;record-audio)))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-discard</span> ()
 <span class="org-doc">"Ignore the previous recording."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">when</span> (process-live-p whisper&#45;&#45;recording-process)
    <span class="org-comment-delimiter">;; </span><span class="org-comment">Remove the sentinel; handle results ourselves</span>
    (set-process-sentinel whisper&#45;&#45;recording-process
                          (<span class="org-keyword">lambda</span> (process event)
                            (<span class="org-keyword">when</span> (file-exists-p whisper&#45;&#45;temp-file)
                              (delete-file whisper&#45;&#45;temp-file))
                            (my-whisper-process-queue)))
    (interrupt-process whisper&#45;&#45;recording-process)))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-discard-and-continue</span> ()
 <span class="org-doc">"Ignore the previous recording and continue."</span>
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">if</span> (process-live-p whisper&#45;&#45;recording-process)
      (<span class="org-keyword">progn</span>
        <span class="org-comment-delimiter">;; </span><span class="org-comment">Remove the sentinel; handle results ourselves</span>
        (set-process-sentinel whisper&#45;&#45;recording-process
                              (<span class="org-keyword">lambda</span> (process event)
                                (my-whisper-process-queue)
                                (my-whisper-continue)))
        (interrupt-process whisper&#45;&#45;recording-process))
    (my-whisper-continue)))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-done</span> ()
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">when</span> (process-live-p whisper&#45;&#45;recording-process)
    (add-to-list
     <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">my-whisper&#45;&#45;queue</span>
     (list <span class="org-builtin">:file</span> whisper&#45;&#45;temp-file
           <span class="org-builtin">:buffer</span>
           (format <span class="org-string">"*result: %s*"</span> (file-name-base whisper&#45;&#45;temp-file)))
     t)
    <span class="org-comment-delimiter">;; </span><span class="org-comment">Remove the sentinel; handle results ourselves</span>
    (set-process-sentinel whisper&#45;&#45;recording-process
                          (<span class="org-keyword">lambda</span> (process event)
                            (my-whisper-process-queue)))
    (whisper&#45;&#45;setup-mode-line <span class="org-builtin">:hide</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">recording</span>)
    (interrupt-process whisper&#45;&#45;recording-process)))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-process-queue-result</span> ()
  <span class="org-doc">"Process the first part of the queue that already has results."</span>
  (<span class="org-keyword">while</span> (plist-get (car my-whisper&#45;&#45;queue) <span class="org-builtin">:results</span>)
    (<span class="org-keyword">let</span> ((o (<span class="org-keyword">pop</span> my-whisper&#45;&#45;queue)))
      (<span class="org-keyword">unless</span> my-whisper-target-markers
        (<span class="org-keyword">setq</span> whisper&#45;&#45;marker (point-marker)
              whisper&#45;&#45;point-buffer (current-buffer)))
      (<span class="org-keyword">with-current-buffer</span> (plist-get o <span class="org-builtin">:buffer</span>)
        (erase-buffer)
        (insert (plist-get o <span class="org-builtin">:results</span>)))
      <span class="org-comment-delimiter">;; </span><span class="org-comment">Only works with my fork: https://github.com/sachac/whisper.el/tree/whisper-insert-text-at-point-function</span>
      (whisper&#45;&#45;handle-transcription-output nil (plist-get o <span class="org-builtin">:buffer</span>)))))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-process-queue</span> ()
  (<span class="org-keyword">let</span> (o)
    (<span class="org-keyword">while</span> (<span class="org-keyword">setq</span> o (seq-find (<span class="org-keyword">lambda</span> (o) (<span class="org-keyword">and</span> (plist-get o <span class="org-builtin">:file</span>)
                                              (not (plist-get o <span class="org-builtin">:process</span>))
                                              (not (plist-get o <span class="org-builtin">:results</span>))))
                             my-whisper&#45;&#45;queue))
      (<span class="org-keyword">let*</span> ((headers (list <span class="org-string">"Content-Type: multipart/form-data"</span>))
             (params (list (concat <span class="org-string">"file=@"</span>
                                   (plist-get o <span class="org-builtin">:file</span>))
                           <span class="org-string">"temperature=0.0"</span>
                           <span class="org-string">"temperature_inc=0.2"</span>
                           <span class="org-string">"response_format=json"</span>
                           (concat <span class="org-string">"model="</span> whisper-model)
                           (concat <span class="org-string">"language="</span> whisper-language)))
             (url (format my-whisper-url-format whisper-server-host whisper-server-port))
             (command <span class="org-highlight-quoted-quote">`</span>(<span class="org-string">"curl"</span> <span class="org-string">"-s"</span>
                        ,url
                        ,@(mapcan (<span class="org-keyword">lambda</span> (h) (list <span class="org-string">"-H"</span> h)) headers)
                        ,@(mapcan (<span class="org-keyword">lambda</span> (p) (list <span class="org-string">"-F"</span> p)) params))))
        (<span class="org-keyword">with-current-buffer</span> (get-buffer-create (plist-get o <span class="org-builtin">:buffer</span>))
          (erase-buffer))
        (plist-put
         o <span class="org-builtin">:process</span>
         (make-process
          <span class="org-builtin">:name</span> <span class="org-string">"whisper-curl"</span>
          <span class="org-builtin">:command</span> command
          <span class="org-builtin">:buffer</span> (plist-get o <span class="org-builtin">:buffer</span>)
          <span class="org-builtin">:coding</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">utf-8</span>
          <span class="org-builtin">:sentinel</span>
          (<span class="org-keyword">lambda</span> (process event)
            (<span class="org-keyword">with-current-buffer</span> (process-buffer process)
              (<span class="org-keyword">let</span> ((current my-whisper&#45;&#45;queue-item))
                (<span class="org-keyword">when</span> (<span class="org-keyword">and</span> (get-buffer (plist-get current <span class="org-builtin">:buffer</span>))
                           (string-equal <span class="org-string">"finished\n"</span> event))
                  (<span class="org-keyword">with-current-buffer</span> (plist-get current <span class="org-builtin">:buffer</span>)
                    (goto-char (point-min))
                    (plist-put current <span class="org-builtin">:results</span>
                               (<span class="org-keyword">or</span>
                                (<span class="org-keyword">condition-case</span> nil
                                    (gethash <span class="org-string">"text"</span> (json-parse-buffer))
                                  (<span class="org-warning">error</span> <span class="org-string">""</span>))
                                <span class="org-string">"(error)"</span>))))))
            (my-whisper-process-queue-result))))
        (plist-put o <span class="org-builtin">:command</span> (string-join command <span class="org-string">" "</span>))
        (<span class="org-keyword">with-current-buffer</span> (process-buffer (plist-get o <span class="org-builtin">:process</span>))
          (<span class="org-keyword">setq-local</span> my-whisper&#45;&#45;queue-item o))))))
(<span class="org-keyword">defvar-local</span> <span class="org-variable-name">my-whisper&#45;&#45;queue-item</span> nil)

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-reprocess-queue</span> ()
  (<span class="org-keyword">interactive</span>)
  (<span class="org-keyword">setq</span> whisper&#45;&#45;marker (point-marker) whisper&#45;&#45;point-buffer (current-buffer))
  (mapc (<span class="org-keyword">lambda</span> (o)
          (<span class="org-keyword">when</span> (process-live-p (plist-get o <span class="org-builtin">:process</span>))
            (kill-process (plist-get o <span class="org-builtin">:process</span>)))
          (<span class="org-keyword">when</span> (get-buffer (plist-get o <span class="org-builtin">:buffer</span>))
            (kill-buffer (plist-get o <span class="org-builtin">:buffer</span>)))
          (plist-put o <span class="org-builtin">:process</span> nil)
          (plist-put o <span class="org-builtin">:results</span> nil))
        my-whisper&#45;&#45;queue)
  (my-whisper-process-queue))

(<span class="org-keyword">defun</span> <span class="org-function-name">my-whisper-clear-queue</span> ()
  (<span class="org-keyword">interactive</span>)
  (mapc (<span class="org-keyword">lambda</span> (o)
          (<span class="org-keyword">when</span> (process-live-p (plist-get o <span class="org-builtin">:process</span>))
            (kill-process (plist-get o <span class="org-builtin">:process</span>)))
          (<span class="org-keyword">when</span> (get-buffer (plist-get o <span class="org-builtin">:buffer</span>))
            (kill-buffer (plist-get o <span class="org-builtin">:buffer</span>)))
          (plist-put o <span class="org-builtin">:process</span> nil)
          (plist-put o <span class="org-builtin">:results</span> nil))
        my-whisper&#45;&#45;queue)
  (<span class="org-keyword">setq</span> my-whisper&#45;&#45;queue nil))

(keymap-global-set <span class="org-string">"&lt;kp-9&gt;"</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">my-whisper-continue</span>)
(keymap-global-set <span class="org-string">"&lt;kp-8&gt;"</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">my-whisper-discard-and-continue</span>)
(keymap-global-set <span class="org-string">"C-&lt;kp-9&gt;"</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">my-whisper-done</span>)
</code></pre>
</div>

</details>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-queue-multiple-transcriptions-with-whisper-el-speech-recognition">Emacs configuration.</a></div><div><a href="https://sachachua.com/blog/2026/01/queue-multiple-transcriptions-with-whisper-el-speech-recognition/index.org">View org source for this post</a></div><p>You can <a href="https://social.sachachua.com/@sacha/statuses/01KFP6RDJ52ERX664SPP6CN7S9" target="_blank" rel="noopener noreferrer">comment on Mastodon</a> or <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F01%2Fqueue-multiple-transcriptions-with-whisper-el-speech-recognition%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry><entry>
		<title type="html">Emacs and whisper.el: Trying out different speech-to-text backends and models</title>
		<link rel="alternate" type="text/html" href="https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/"/>
		<author><name><![CDATA[Sacha Chua]]></name></author>
		<updated>2026-01-20T19:21:46Z</updated>
    <published>2026-01-20T19:21:46Z</published>
    <category term="audio" />
<category term="emacs" />
<category term="speech-recognition" />
		<id>https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/</id>
		<content type="html"><![CDATA[<p>
Update <span class="timestamp-wrapper"><time class="timestamp" datetime="2026-10-06">[2026-10-06 Tue]</time></span>: I'm currently using Orukeet instead of Whisper/Speaches. <a href="https://sachachua.com/blog/2026/09/experimenting-with-orukeet-for-speech-recognition/">Experimenting with Orukeet for speech recognition</a>
</p>

<p>
I was curious about <a href="https://parakeettdt.com/">parakeet</a> because I heard that it was faster than Whisper on the <a href="https://huggingface.co/spaces/hf-audio/open_asr_leaderboard">HuggingFace leaderboard</a>. When I installed it and got it running on my laptop (CPU only, no GPU), it seemed like my results were a little faster than whisper.cpp with the large model, but much slower than whisper.cpp with the base model. The base model is decent for quick dictation, so I got curious about other backends and other models.
</p>

<p>
In order to try <a href="https://github.com/natrys/whisper.el">natrys/whisper.el</a> with other backends, I needed to work around how whisper.el validates the model names and sends requests to the servers. Here's the quick and dirty code for doing so, in case you want to try it out for yourself.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-whisper-url-format</span> <span class="org-string">"http://%s:%d/transcribe"</span>)
<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-whisper&#45;&#45;transcribe-via-local-server</span> ()
  <span class="org-doc">"Transcribe audio using the local whisper server."</span>
  (message <span class="org-string">"[-] Transcribing via local server"</span>)
  (whisper&#45;&#45;setup-mode-line <span class="org-builtin">:show</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">transcribing</span>)
  (whisper&#45;&#45;ensure-server)
  (<span class="org-keyword">setq</span> whisper&#45;&#45;transcribing-process
        (whisper&#45;&#45;process-curl-request
         (format sacha-whisper-url-format whisper-server-host whisper-server-port)
         (list <span class="org-string">"Content-Type: multipart/form-data"</span>)
         (list (concat <span class="org-string">"file=@"</span> whisper&#45;&#45;temp-file)
               <span class="org-string">"temperature=0.0"</span>
               <span class="org-string">"temperature_inc=0.2"</span>
               <span class="org-string">"response_format=json"</span>
               (concat <span class="org-string">"model="</span> whisper-model)
               (concat <span class="org-string">"language="</span> whisper-language)))))
<span class="org-comment-delimiter">;;;</span><span class="org-comment">###</span><span class="org-comment"><span class="org-warning">autoload</span></span>
(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-whisper&#45;&#45;check-model-consistency</span> () t)
</code></pre>
</div>


<p>
I moved my server code to <a href="https://codeberg.org/sachac/speech-input/src/branch/main/speech-input-speaches.el">speech-input-speaches.el</a>.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">with-eval-after-load</span> <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper</span>
  (advice-add <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper&#45;&#45;transcribe-via-local-server</span> <span class="org-builtin">:override</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">sacha-whisper&#45;&#45;transcribe-via-local-server</span>)
  (advice-add <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">whisper&#45;&#45;check-model-consistency</span> <span class="org-builtin">:override</span> <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">sacha-whisper&#45;&#45;check-model-consistency</span>)
  <span class="org-comment-delimiter">;;</span><span class="org-comment">(advice-add 'whisper&#45;&#45;ensure-server :override #'speech-input-speaches-server-start)</span>
  )
</code></pre>
</div>


<p>
Then I have this function for trying things out.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-test-whisper-api</span> (url <span class="org-type">&amp;optional</span> args)
  (<span class="org-keyword">with-temp-buffer</span>
    (apply <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">call-process</span> <span class="org-string">"curl"</span> nil t nil <span class="org-string">"-s"</span>
           url
         (append (mapcan
                  (<span class="org-keyword">lambda</span> (h) (list <span class="org-string">"-H"</span> h))
                  (list <span class="org-string">"Content-Type: multipart/form-data"</span>))
                 (mapcan
                  (<span class="org-keyword">lambda</span> (h) (list <span class="org-string">"-F"</span> h))
                  (list (concat <span class="org-string">"file=@"</span> whisper&#45;&#45;temp-file)
                        <span class="org-string">"temperature=0.0"</span>
                        <span class="org-string">"temperature_inc=0.2"</span>
                        <span class="org-string">"response_format=verbose_json"</span>
                        (concat <span class="org-string">"language="</span> whisper-language)))
                 args))
    (message <span class="org-string">"%s %s"</span> (buffer-string) url)))
</code></pre>
</div>


<p>
Here's the audio file. It is around 10 seconds long. I run the benchmark 3 times and report the average time.
</p>

<p>
</p><div class="audio"><audio controls="1" preload="metadata" src="https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/2026-01-19-14-17-53.wav?2026-10-06" type="audio/x-wav"><a href="https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/2026-01-19-14-17-53.wav">Download the audio</a></audio></div>
<a href="https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/2026-01-19-14-17-53.wav">Download</a>
<p></p>

<details><summary>Code for running the benchmarks</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp" id="orgf855d0b"><code>(<span class="org-keyword">let</span> ((times <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">3</span>))
(mapcar
 (<span class="org-keyword">lambda</span> (group)
   (<span class="org-keyword">let</span> ((whisper&#45;&#45;temp-file <span class="org-string">"/home/sacha/recordings/whisper/2026-01-19-14-17-53.wav"</span>))
     <span class="org-comment-delimiter">;; </span><span class="org-comment">warm up the model</span>
     (eval (cadr group))
     (list
      (format <span class="org-string">"%.3f"</span>
              (/ (car
                  (benchmark-call (<span class="org-keyword">lambda</span> () (eval (cadr group))) times))
                 times))
      (car group))))
 <span class="org-highlight-quoted-quote">'</span>(
   (<span class="org-string">"parakeet"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 5092)))
   (<span class="org-string">"whisper.cpp base-q4_0"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/inference"</span> whisper-server-host 8642)))
   (<span class="org-string">"speaches whisper-base"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 8001)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-base"</span>)))
   (<span class="org-string">"speaches whisper-base.en"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 8001)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-base.en"</span>)))
   (<span class="org-string">"speaches whisper-small"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 8001)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-small"</span>)))
   (<span class="org-string">"speaches whisper-small.en"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 8001)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-small.en"</span>)))
   (<span class="org-string">"speaches lorneluo/whisper-small-ct2-int8"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> whisper-server-host 8001)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=lorneluo/whisper-small-ct2-int8"</span>)))
   <span class="org-comment-delimiter">;; </span><span class="org-comment">needed export TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1</span>
   (<span class="org-string">"whisperx-server Systran/faster-whisper-small"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/transcribe"</span> whisper-server-host 8002)))))
)
</code></pre>
</div>

</details>

<table>


<colgroup>
<col class="org-right">

<col class="org-left">
</colgroup>
<tbody>
<tr>
<td class="org-right">3.694</td>
<td class="org-left">parakeet</td>
</tr>

<tr>
<td class="org-right">2.484</td>
<td class="org-left">whisper.cpp base-q4_0</td>
</tr>

<tr>
<td class="org-right">1.547</td>
<td class="org-left">speaches whisper-base</td>
</tr>

<tr>
<td class="org-right">1.425</td>
<td class="org-left">speaches whisper-base.en</td>
</tr>

<tr>
<td class="org-right">4.076</td>
<td class="org-left">speaches whisper-small</td>
</tr>

<tr>
<td class="org-right">3.735</td>
<td class="org-left">speaches whisper-small.en</td>
</tr>

<tr>
<td class="org-right">2.870</td>
<td class="org-left">speaches lorneluo/whisper-small-ct2-int8</td>
</tr>

<tr>
<td class="org-right">4.537</td>
<td class="org-left">whisperx-server Systran/faster-whisper-small</td>
</tr>
</tbody>
</table>

<p>
All the results above were CPU-only, no GPU acceleration.
</p>

<p>
I tried it with:
</p>
<ul class="org-ul">
<li><a href="https://parakeettdt.com/">parakeet</a></li>
<li><a href="https://huggingface.co/ggerganov/whisper.cpp">whisper.cpp</a> (as <a href="https://github.com/natrys/whisper.el">whisper.el</a> sets it up)</li>
<li><a href="https://github.com/speaches-ai/speaches">speaches</a>, which is a front-end for <a href="https://github.com/SYSTRAN/faster-whisper">faster-whisper</a>, and</li>
<li><a href="https://codeberg.org/aryak/whisperx-server">whisperx-server</a>, which is a front-end for <a href="https://github.com/m-bain/whisperX">whisperx</a></li>
</ul>

<div class="update" id="org3d8de14">
<p>
<span class="timestamp-wrapper"><time class="timestamp" datetime="2026-04-05">[2026-04-05 Sun]</time></span> Update: After a lot of rebooting, I figured out how to get the Nvidia P1000 GPU on my Lenovo P52 to work for up to the Whisper medium models. Large models don't fit in the 4GB of VRAM it has. Here are the benchmarking results:
</p>

<details><summary>Benchmarking code</summary>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">let</span> ((times <span class="org-highlight-quoted-quote">'</span><span class="org-highlight-quoted-symbol">3</span>))
(mapcar
 (<span class="org-keyword">lambda</span> (group)
   (<span class="org-keyword">let</span> ((whisper&#45;&#45;temp-file <span class="org-string">"/tmp/2026-01-19-14-17-53.wav"</span>))
     <span class="org-comment-delimiter">;; </span><span class="org-comment">warm up the model</span>
     (eval (cadr group))
     (list
      (format <span class="org-string">"%.3f"</span>
              (/ (car
                  (benchmark-call (<span class="org-keyword">lambda</span> () (eval (cadr group))) times))
                 times))
      (car group))
     ))
 <span class="org-highlight-quoted-quote">'</span>(
   (<span class="org-string">"speaches whisper-tiny"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> <span class="org-string">"localhost"</span> 8000)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-tiny.en"</span>)))
   (<span class="org-string">"speaches whisper-base"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> <span class="org-string">"localhost"</span> 8000)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-base.en"</span>)))
   (<span class="org-string">"speaches whisper-small"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> <span class="org-string">"localhost"</span> 8000)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-small.en"</span>)))
   (<span class="org-string">"speaches whisper-medium"</span>
    (sacha-test-whisper-api
     (format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span> <span class="org-string">"localhost"</span> 8000)
     (list <span class="org-string">"-F"</span> <span class="org-string">"model=Systran/faster-whisper-medium.en"</span>))))))
</code></pre>
</div>

</details>

<table>


<colgroup>
<col class="org-right">

<col class="org-left">
</colgroup>
<tbody>
<tr>
<td class="org-right">0.596</td>
<td class="org-left">speaches whisper-tiny</td>
</tr>

<tr>
<td class="org-right">0.940</td>
<td class="org-left">speaches whisper-base</td>
</tr>

<tr>
<td class="org-right">2.909</td>
<td class="org-left">speaches whisper-small</td>
</tr>

<tr>
<td class="org-right">8.740</td>
<td class="org-left">speaches whisper-medium</td>
</tr>
</tbody>
</table>

<p>
That probably means I can upgrade to using the small model on a regular basis. For large models, I can use the command-line tool, since the overhead of loading the model is probably small compared to the processing time. I could also run two Speaches servers (one on CPU and one on GPU), but I don't think I'll need that level yet.
</p>

</div>

<p>
I like how speaches lets me switch models on the fly, so maybe I can use small.en generally and switch to a different model when I want to try dictating in French. Here's how I've set it up to use the server.
</p>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">defvar</span> <span class="org-variable-name">sacha-speech-input-model-aliases</span>
  <span class="org-highlight-quoted-quote">'</span>((<span class="org-string">"small"</span> . <span class="org-string">"Systran/faster-whisper-small.en"</span>)
    (<span class="org-string">"medium"</span> . <span class="org-string">"Systran/faster-whisper-medium.en"</span>)
    (<span class="org-string">"base"</span> . <span class="org-string">"Systran/faster-whisper-base.en"</span>)
    (<span class="org-string">"tiny"</span> . <span class="org-string">"Systran/faster-whisper-tiny.en"</span>)
    (<span class="org-string">"large"</span> . <span class="org-string">"Systran/faster-whisper-large-v2"</span>)))

(<span class="org-keyword">defun</span> <span class="org-function-name">sacha-speech-input-set-model</span> (model-name)
  <span class="org-doc">"Change the speech recognition model to MODEL-NAME.</span>
<span class="org-doc">Use `</span><span class="org-doc"><span class="org-constant">sacha-speech-input-model-aliases</span></span><span class="org-doc">' for aliases."</span>
  (<span class="org-keyword">interactive</span> (list (speech-input-speaches-read-model-name)))
  (<span class="org-keyword">when</span> (assoc-default model-name sacha-speech-input-model-aliases <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">string=</span>)
    (<span class="org-keyword">setq</span> model-name (assoc-default model-name sacha-speech-input-model-aliases <span class="org-highlight-quoted-quote">#'</span><span class="org-highlight-quoted-symbol">string=</span>)))
  (<span class="org-keyword">setq</span> whisper-model model-name)
  (<span class="org-keyword">setq</span> speech-input-model model-name
        speech-input-transcribe-model model-name))
</code></pre>
</div>


<div class="org-src-container">
<pre class="src src-emacs-lisp"><code>(<span class="org-keyword">setq</span> whisper-model <span class="org-string">"Systran/faster-whisper-small.en"</span>
      sacha-whisper-url-format <span class="org-string">"http://%s:%d/v1/audio/transcriptions"</span>)
</code></pre>
</div>


<p>
Benchmark notes: I have a Lenovo P52 laptop (released 2018) with an Intel Core i7-8850H (6 cores, 12 threads; 2.6 GHz base / 4.3 GHz turbo) with 64GB RAM and an SSD. It has a soldered-on Nvidia P1000 with 4GB of VRAM.
</p>

<div class="note">This is part of my <a href="https://sachachua.com/dotemacs#writing-and-editing-speech-recognition-emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models">EmacsConfiguration.</a></div><div><a href="https://sachachua.com/blog/2026/01/emacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models/index.org">View Org source for this post</a></div><p>You can <a href="https://social.sachachua.com/@sacha/statuses/01KFERY839GS115F3J8Z6BNT1K" target="_blank" rel="noopener noreferrer">comment on Mastodon</a> or <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2026%2F01%2Femacs-and-whisper-el-trying-out-different-speech-to-text-backends-and-models%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></content>
		</entry>
</feed>