Morse Code - XML

This guide dives into how to incorporate morse code into your XML bins.

Overview

This project is powered by SignalWire Compatible XML using XML Bins, a server-less way to run your XML documents. As a way to help you get started, see the code below to form your own ASR --> Morse interface!

What do I need to run this application?

Demo

We've set up a little demonstration for anyone interested in trying this out; simply call 838-66-MORSE!

Build it Yourself!

Because XML bins are server-less, all you will need is a SignalWire account, which you can sign up for here. If you aren't sure what XML bins are or how to use them, check out THIS quick-start guide.

Step by Step Walkthrough

1. Welcome to Morse

The below XML bin is based on the <Say> verb. Our narrator will begin by speaking in English and introduce the game that will be played. Notice that the <Redirect> verb is used to transition into the next XML bin in the call flow.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>
    <break strength="x-weak" time="200ms"/>
    <prosody pitch="+10%">In this day and age, some people forget where they came from. But not us here at Signal-Wire!</prosody> 
    <break strength="x-weak" time="300ms"/>
  </Say>
  <Say>
    <prosody pitch="+10%">To celebrate our heritage, let's kick this party <emphasis level="moderate">old-school style</emphasis> for a few minutes with some<say-as interpret-as="expletive">super cool</say-as> morse code.</prosody>
  </Say>
  <Redirect>https://morsecode.signalwire.com/laml-bins/d0234d15-6f4a-4f99-a0e6-9d6cbbf412cb</Redirect>;
</Response>

2. Let's get a name shall we?

Notice the usage of the <Gather> verb to take in the caller's answer to 'What's your name?'.
Once the Caller gives their input, they will be passed to the next bin in the call flow using the action URL.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather input="speech" speechTimeout="auto" action="https://morsecode.signalwire.com/laml-bins/e17a3ac4-fe21-427c-8796-e8ddadd98374">;
    <Say><break strength="x-weak" time="200ms"/><prosody pitch="+10%">Tell me: what's your name?</prosody></Say>
  </Gather>
</Response>

3. Let's play your name in Morse (with some Mustache templating to grab speech results)!

Because our call was passed from the <Gather> action, we now have access to the Caller's input with the {{SpeechResult}} mustache templating.

In this step, the <Say> verb is being amended with language="morse" This will translate our mustache variable {{SpeechResult}} into morse code and speak it back to us.

After this, it will redirect us to the next bin in our call flow.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say><prosody pitch="+10%">So, {{SpeechResult}}, here is me saying your name in morse code:</prosody></Say>
  <Say language="morse">{{SpeechResult}}</Say>
  <Redirect method="GET">https://morsecode.signalwire.com/laml-bins/5e266f7b-526c-43ac-810d-2d82b5e43f22?name={{SpeechResult}}</Redirect>
</Response>

4. Now let's keep the fun going with speech recognition on full sentences!

The <Gather> verb will now take in a larger speech input of a full sentence that the user would like translated. If the caller provides us a sentence, we will redirect to the final bin in our call flow with the action URL once again.

If nothing is said, the <Gather> verb will terminate and the call will begin the process of ending.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather input="speech" speechTimeout="auto" action="https://morsecode.signalwire.com/laml-bins/db6ea71a-ac66-4207-a2cd-28803a68ffc9?name={{name}}">
    <say><prosody pitch="+10%">Speak whatever you want, and I'll say it in morse code.</prosody></Say>
  </Gather>
  <Say><prosody pitch="+10%">I suppose history means nothing to you {{name}}! Well then, good day sir!</prosody></Say>
</Response>

5. Speak the results.

The mustache variable {{SpeechResult}} that was gathered from the user's speech entry will once again be repeated back to the user in morse code.

At this point, <Redirect> will actually send us back to the previous bin and allow the user to try out a new sentence offering a sort of 'loop' between the two. Without this <Redirect> the call would end, and users would have to call back to try again.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say><prosody pitch="+10%"">That would be:</prosody></Say>
  <Say language="morse" voice="woman">{{SpeechResult}}</Say>
  <Say><prosody pitch="+10%">I've waited years for this moment {{name}}. Let's keep it going.</prosody></Say>
  <Redirect>https://morsecode.signalwire.com/laml-bins/5e266f7b-526c-43ac-810d-2d82b5e43f22</Redirect>;
</response>

Wrap Up

XML bins are an awesome tool accessible directly within your SignalWire space! While they are not as feature-rich as our Compatibility API or Communications API, bins can be used to perform simple tasks, or chained together to build some creative projects like this one!

Resources

How To Create and Use XML Bins
SignalWire Compatible XML QuickStart Guide

Sign Up Here

If you would like to test this example out, you can create a SignalWire account and space here.

Please feel free to reach out to us on our Community Slack or create a Support ticket if you need guidance!


Did this page help you?