<?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>techno.blog(&#34;Dion&#34;) &#187; speech</title>
	<atom:link href="http://almaer.com/blog/tag/speech/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Tue, 28 Aug 2012 14:41:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Chrome Speak To Site; Give any input the power to listen to you</title>
		<link>http://almaer.com/blog/chrome-speak-to-site-give-any-input-the-power-to-listen-to-you</link>
		<comments>http://almaer.com/blog/chrome-speak-to-site-give-any-input-the-power-to-listen-to-you#comments</comments>
		<pubDate>Tue, 28 Sep 2010 16:34:43 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web Browsing]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[speech]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/?p=2796</guid>
		<description><![CDATA[Paul Irish gave a fantastic updated State of HTML5 talk at JSConf.EU. It is packed full of demos, including sharks with freaking lazer beams!
At one point he showed off the WebKit support for &#60;input speech&#62; implementation that allows you to talk into an input area. You click on the microphone, speak in, and it will [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://paulirish.com/">Paul Irish</a> gave a fantastic updated <a href="http://jsconfeu2010-pi.appspot.com/">State of HTML5</a> talk at JSConf.EU. It is packed full of demos, including sharks with freaking lazer beams!</p>
<p>At one point he showed off the <a href="http://trac.webkit.org/export/66389/trunk/LayoutTests/fast/speech/input-appearance-speechbutton.html">WebKit support for &lt;input speech&gt;</a> implementation that allows you to talk into an input area. You click on the microphone, speak in, and it will get translated for you with the results. I am not sure if you can tweak how the translation is done (choose a Nuance vs. Google vs. &#8230;. solution for example), but it definitely works well out of the box.</p>
<p><img src="http://almaer.com/blog/uploads/speak-to-site.png" alt="speak-to-site" title="speak-to-site" width="509" height="379" class="alignnone size-full wp-image-2797"></p>
<p>I was surprised to see this already landed in my developer-channel Chrome, so I was incented to do something with it on the plane trip back from Berlin to New York City. Something simple would be to give the user the ability to enable speech on any input. I whipped up a Chrome extension using the <a href="http://code.google.com/chrome/extensions/beta/contextMenus.html">context menu API</a>, but was quickly surprised to see that there isn&#8217;t <a href="http://code.google.com/p/chromium/issues/detail?id=39507">support in the API to get the DOM node that you are working on</a>. Huh. Kinda crazy in fact.</p>
<p>Then the whizzkid <a href="http://antimatter15.com/wp/2010/08/chrome-extension-hide-element/">antimatter came to the rescue</a> with his cheeky little hack around the system. Here is how it plays out in the world of this extension:</p>
<p><b>The background page</b></p>
<p>First we enable the context menu on any &#8220;editable&#8221; element (vs. anywhere on the page, on any text, etc), and when clicked we fire off an event to the content script in the given tab:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
chrome.<span style="color: #660066;">contextMenus</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Turn on speech input&quot;</span><span style="color: #339933;">,</span>
    contexts<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;editable&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    onclick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>info<span style="color: #339933;">,</span> tab<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">sendRequest</span><span style="color: #009900;">&#40;</span>tab.<span style="color: #660066;">id</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'letmespeak'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><b>Catching in a content script</b></p>
<p>A content script then does two things:</p>
<ul>
<li>Listens for mousedown events to keep resetting the last element in focus
<li>Catches the event, and turns on the speech attribute on the target DOM node
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> last_target <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousedown'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    last_target <span style="color: #339933;">=</span> event.<span style="color: #660066;">target</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
chrome.<span style="color: #660066;">extension</span>.<span style="color: #660066;">onRequest</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    last_target.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;speech&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;on&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    last_target <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p><b>Wire-y wire-y</b></p>
<p>Of course, it all gets wired up in the manifest:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Turn on Speech Input&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Turns on the speech attribute, allows you to speak into an input&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0.1&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;permissions&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;contextMenus&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;minimum_chrome_version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;6&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;background_page&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;background.html&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;content_scripts&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;matches&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;&lt;all_urls&gt;&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;js&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;input-speech.js&quot;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This <a href="http://github.com/dalmaer/chrome-speaktosite/raw/master/chrome-speaktosite.crx">trivial extension</a> is <a href="http://github.com/dalmaer/chrome-speaktosite">of course on GitHub</a> (I want <a href="http://thechangelog.com/post/1200486354/git-achievements-aquire-achievements-while-using-git">git-achivements</a> after all! :).</p>
<p>A couple of things trouble me though:</p>
<ul>
<li>The microphone icon should sit on the right of the input, however when dynamically tweaked like this it shows up on the left by mistake [BUG]
<li>I have also played with extensions such as <a href="https://chrome.google.com/extensions/detail/jlhhbmloafbaonaondjcedenomeeggda">Google Scribe</a>. Adding icons like this doesn&#8217;t scale. Having them show up all the time gets in my way. I think I want one ability to popup special powers like scribe completion, or speech-to-text, without it getting in my way
<li>When services are built into standard elements like this, it feels like I want to have the ability to tweak how they work (with great defaults of course, as 99.9999% of the time they won&#8217;t be changed.
</ul>
<p>You?</p>
]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/chrome-speak-to-site-give-any-input-the-power-to-listen-to-you/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
