Friday Fun Trick: Turning Text into Morse Code, Vice Versa, in PowerShell

0

Called dots and dashes, Morse Code is one of the oldest methods used to transmit text characters in standardized sequences of two different signal durations. Here, we are going to use one of the free web APIs out there to turn any text you input into Morse Code or vice versa, all in PowerShell.

$Text = Read-Host 'Text to Morse'
 
# URL-encode text
Add-Type -AssemblyName System.Web
$encoded = [System.Web.HttpUtility]::UrlEncode($Text)
 
# compose web service URL
$Url = 'https://api.funtranslations.com/translate/morse.json?text=' + $encoded
 
# call web service
(Invoke-RestMethod -UseBasicParsing -Uri $url).contents.translated
image 13 600x150 - Friday Fun Trick: Turning Text into Morse Code, Vice Versa, in PowerShell

To convert a series of Morse Code back to plain English version, simply replace the API to Morse2English.

$Text = Read-Host 'Morse to Text'
 
# URL-encode text
Add-Type -AssemblyName System.Web
$encoded = [System.Web.HttpUtility]::UrlEncode($Text)
 
# compose web service URL
$Url = 'https://api.funtranslations.com/translate/morse2english.json?text=' + $encoded
 
# call web service
(Invoke-RestMethod -UseBasicParsing -Uri $url).contents.translated
image 14 600x135 - Friday Fun Trick: Turning Text into Morse Code, Vice Versa, in PowerShell

Note that the free web API limits to only 5 request calls per hour so use it wisely.

Thanks to PowerTips for this awesome trick. If you want to create the real beeps based on the Morse Code, check it out.

LEAVE A REPLY

Please enter your comment!
Please enter your name here