<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LaunchBar &#8211; jaguchi log</title>
	<atom:link href="https://jaguchi.com/blog/tag/launchbar/feed/" rel="self" type="application/rss+xml" />
	<link>https://jaguchi.com</link>
	<description>Speeding on training wheels</description>
	<lastBuildDate>Thu, 10 Sep 2020 00:22:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://jaguchi.com/wp-content/uploads/2017/02/cropped-low_res-32x32.png</url>
	<title>LaunchBar &#8211; jaguchi log</title>
	<link>https://jaguchi.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">149953163</site>	<item>
		<title>LaunchBar action to generate spoken audio files</title>
		<link>https://jaguchi.com/blog/2018/09/launchbar-action-to-generate-spoken-audio-files/</link>
		
		<dc:creator><![CDATA[mirka]]></dc:creator>
		<pubDate>Mon, 24 Sep 2018 14:11:42 +0000</pubDate>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[LaunchBar]]></category>
		<category><![CDATA[AppleScript]]></category>
		<guid isPermaLink="false">https://jaguchi.com/?p=944</guid>

					<description><![CDATA[Combine the macOS Speech Synthesis CLI with a LaunchBar action to instantly create spoken audio files. Great for Anki flashcards!]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">You may know that macOS comes with a rather powerful text-to-speech system. It&#8217;s capable of speaking text in different languages, and can be triggered via <a href="https://support.apple.com/kb/ph25639">keyboard shortcut</a>&nbsp;or the &#8220;Speech&#8221; context menu.</p>



<p class="wp-block-paragraph">A lesser-known fact is that it has a command line interface.</p>



<span id="more-944"></span>



<pre class="wp-block-code"><code lang="bash" class="language-bash">$ say "hello world"</code></pre>



<p class="wp-block-paragraph">This CLI offers some useful options, like specifying a voice and saving to file. By pairing this with <a href="https://obdev.at/products/launchbar/">LaunchBar</a>, we can build actions that take text input and instantly generate a spoken audio file.&nbsp;I&#8217;ve been using this to add spoken audio files to my <a href="https://apps.ankiweb.net/">Anki</a> flashcards:</p>



<div class="wp-block-image aligncenter"><figure class="aligncenter"><img fetchpriority="high" decoding="async" width="480" height="240" data-attachment-id="945" data-permalink="https://jaguchi.com/blog/2018/09/launchbar-action-to-generate-spoken-audio-files/speak-launchbar/" data-orig-file="https://jaguchi.com/wp-content/uploads/2018/09/speak-launchbar.gif" data-orig-size="480,240" data-comments-opened="0" data-image-title="speak-launchbar" data-image-description="" data-image-caption="" data-large-file="https://jaguchi.com/wp-content/uploads/2018/09/speak-launchbar.gif" src="https://jaguchi.com/wp-content/uploads/2018/09/speak-launchbar.gif" alt="" class="wp-image-945"/><figcaption><a href="https://www.obdev.at/resources/launchbar/help/InstantSend.html">Instant send</a> the text to LaunchBar, invoke the action, and get the generated audio file. Ridiculously fast!</figcaption></figure></div>



<p class="wp-block-paragraph">I used to go to <a href="https://forvo.com/">Forvo</a> to get audio spoken by actual humans, but there were too many downsides to this. The audio quality, volume, and accents are inconsistent, and it gets pretty tedious when you&#8217;re making lots of new flashcards each day. I also find it more effective to have my audio files include <a href="https://en.wikipedia.org/wiki/Article_(grammar)">articles</a> when learning gendered nouns. And sometimes, you just want to learn a specific phrase that isn&#8217;t available on Forvo.</p>



<p class="wp-block-paragraph">The built-in speech synthesis CLI + LaunchBar combo is the perfect solution for this.</p>



<h2 class="wp-block-heading">Download on GitHub</h2>



<p class="wp-block-paragraph"><em>Update (Sep 10, 2020) — A more feature-packed polyglot version of this script, as well as my other LaunchBar actions, are now <a href="https://github.com/mirka/launchbar-actions">available on GitHub</a>. The rest of this page may be out of date.</em></p>



<h2 class="wp-block-heading">How to set up</h2>



<p class="wp-block-paragraph">First, go to System Preferences&nbsp;▸ Accessibility&nbsp;▸ Speech, and make sure you&#8217;ve installed the voice you want to use.</p>



<p class="wp-block-paragraph">Next, here&#8217;s the AppleScript we&#8217;ll be using as the LaunchBar action. The way I have it set up, the text is spoken by the voice chosen in the Accessibility settings, and the audio is saved as an .m4a file in my system&#8217;s temporary folder (so as not to clutter my desktop). You should alter this script to meet your exact needs. For example, you might want to add a voice argument to the shell script (e.g. <code>-v alex</code>) to specify a certain voice.</p>



<pre class="wp-block-code"><code lang="applescript" class="language-applescript">on handle_string(str)
	
	set timeStr to (time of (current date))
	set tempItemsPath to POSIX path of (path to temporary items)
	set filePath to tempItemsPath &amp; timeStr &amp; ".m4a"
	set output to do shell script "say " &amp; quoted form of str &amp; " --data-format=aac -o " &amp; filePath
	
	tell application "LaunchBar"
		set selection to filePath
		activate
	end tell
	
end handle_string</code></pre>



<p class="wp-block-paragraph"><em>Aug 2, 2020: Updated for macOS Catalina</em></p>



<div class="wp-block-file"><a href="https://jaguchi.com/wp-content/uploads/2018/09/speak_text_as_m4a.zip">Speak text as m4a.scpt</a><a href="https://jaguchi.com/wp-content/uploads/2018/09/speak_text_as_m4a.zip" class="wp-block-file__button" download>Download</a></div>



<div class="wp-block-file"><a href="https://jaguchi.com/wp-content/uploads/2018/09/speak_text_as_m4a_catalina.zip">Speak text as m4a.scpt (Catalina)</a><a href="https://jaguchi.com/wp-content/uploads/2018/09/speak_text_as_m4a_catalina.zip" class="wp-block-file__button" download>Download</a></div>



<p class="wp-block-paragraph">Place the .scpt file in your LaunchBar actions folder: <code>~/Library/Application Support/LaunchBar/Actions/</code></p>



<p class="wp-block-paragraph">That&#8217;s it!</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">944</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: jaguchi.com @ 2026-11-16 09:11:44 by W3 Total Cache
-->