<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<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>skill &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/skill/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Thu, 05 Sep 2024 08:10:13 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>skill &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Quick and Dirty Self-Hosted Alexa Skills (2019)]]></title>
		<link>https://shkspr.mobi/blog/2019/09/quick-and-dirty-self-hosted-alexa-skills-2019/</link>
					<comments>https://shkspr.mobi/blog/2019/09/quick-and-dirty-self-hosted-alexa-skills-2019/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Thu, 05 Sep 2019 06:50:44 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[alexa]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[skill]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=32631</guid>

					<description><![CDATA[I hate creating Alexa skills. What should be a 3-click process inevitably ends up requiring trips to multiple websites, to set up weird parameters, and reading outdated tutorials for obsolete libraries.  So this is how to create a self-hosted Skill, using PHP. It runs on your own server and doesn&#039;t require any interaction.  The Skill  At a basic level, all your website has to do is spit out a…]]></description>
										<content:encoded><![CDATA[<p>I hate creating Alexa skills. What should be a 3-click process inevitably ends up requiring trips to multiple websites, to set up weird parameters, and reading outdated tutorials for obsolete libraries.</p>

<p>So this is how to create a self-hosted Skill, using PHP. It runs on your own server and doesn't require any interaction.</p>

<h2 id="the-skill"><a href="https://shkspr.mobi/blog/2019/09/quick-and-dirty-self-hosted-alexa-skills-2019/#the-skill">The Skill</a></h2>

<p>At a basic level, all your website has to do is spit out <a href="https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#standard-response-to-canfulfillintentrequest-launchrequest-or-intentrequest-example">a piece of JSON for Alexa</a> to read out.</p>

<pre><code class="language-php">//   Set the correct header for JSON data
header('Content-Type: application/json');
//   Set the response
$response = [
  "response" =&gt; [
    "outputSpeech" =&gt; [
      "type" =&gt; "PlainText",
      "text" =&gt; "I'm a little teapot"
    ]
  ]
];
echo json_encode($response);
</code></pre>

<p>That's it.</p>

<p>This is perfect for when you have a simple query - "Yo! Alexa! Bus time?" - one question, no parameters.</p>

<p>OK, you can make <a href="https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html#verify-request-sent-by-alexa">sure that the request genuinely came from Alexa</a>, and do all sorts of certificate checks. But why bother? Totally unnecessary for a personal skill.</p>

<p>Obviously, you can do some programming make the text say <code>$whatever</code>.</p>

<p>That was easy, right?</p>

<h2 id="the-amazon-side"><a href="https://shkspr.mobi/blog/2019/09/quick-and-dirty-self-hosted-alexa-skills-2019/#the-amazon-side">The Amazon Side</a></h2>

<p>OK kid, this is where it gets complicated.</p>

<p>For this you will need an Amazon developer account. Getting one is beyond the scope of this tutorial.</p>

<p>Go to <a href="https://developer.amazon.com/alexa/console/ask"></a><a href="https://developer.amazon.com/alexa/console/ask">https://developer.amazon.com/alexa/console/ask</a></p>

<p>Click the "Create Skill" button.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console.png" alt="The button on a website." width="775" height="248" class="aligncenter size-full wp-image-32632"></p>

<p>Give your skill a name. It defaults to USA! USA! USA! English - even though Amazon knows your location and the location of your Echo. If you think AI is hard, that ain't nothing compared to localisation.</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console1.png" alt="Create a new skill screen." width="477" height="300" class="aligncenter size-full wp-image-32633">

<p>You need to select a Custom skill and to "Provision your own endpoint".</p>

<p><img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console2.png" alt="" width="280" height="197" class="aligncenter size-medium wp-image-32635"><img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console3.png" alt="" width="280" height="218" class="aligncenter size-full wp-image-32634"></p>

<p>If you try to use AWS Lambdas you'll be in for a world of pain. Don't even bother - they are a nightmare for a beginner to use.</p>

<p>Now scroll <em>all the way</em> back to the top of the website to click the "Create Skill" button. You'd think that after filling in a form, the "next" button would be at the bottom. But that's too easy. If you think AI is hard, that ain't nothing compared to designing an easy to use form.</p>

<p>We're going to choose the "Start From Scratch" template.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console4.png" alt="" width="745" height="325" class="aligncenter size-full wp-image-32636">
This has nothing to do with the Scratch programming language. Which is a shame, because Scratch is a great language and well designed for complex voice interaction models.</p>

<p>Before doing anything else, set up your "endpoint".  This is the website where you uploaded your PHP file.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console5.png" alt="" width="937" height="356" class="aligncenter size-full wp-image-32637">
Your website needs to support https - you may need to change the certificate type on this page if Amazon has difficulties with it.
Hit "Save Endpoints" - again, it is at the top of the screen. Because people naturally work from the bottom of the form to the top of the form.</p>

<p>Next up, we need a default intent. It doesn't really matter what you put in here. This is not a complex skill which can take multiple routes. We just want something to happen whenever it is launched.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console6.png" alt="" width="693" height="224" class="aligncenter size-full wp-image-32638"></p>

<p>Because Alexa isn't really an AI - we have to give lots of "sample" utterances. So, if you want bus times, you might add "next bus", "buses", "when is my bus" - and every variation you can think of.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console7.png" alt="" width="1090" height="281" class="aligncenter size-full wp-image-32639">
Now hit "Build Model" at the top. Once that's done, go to test.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2019/08/Screenshot_2019-08-22-Alexa-Developer-Console8.png" alt="" width="1110" height="137" class="aligncenter size-full wp-image-32640">
Set the dropdown to "Development".</p>

<p>That's it! You're finally done!  You can test the skill by either typing "whatever" into the text box, or by saying "Alexa! Whatever."</p>

<p>Alexa will read out whatever is in your PHP script.</p>

<p>I wish it were easier. Why can't I just say "When I ask <em>this</em> question, reply with the data from <em>that</em> website."  Sites like IFTTT and Zapier make it so easy to create services - I wish there was a Voice Assistant which was easy to make skills for.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=32631&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2019/09/quick-and-dirty-self-hosted-alexa-skills-2019/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
