

Try not to use my decoder - write your own! I'll leave you with a pair of challenging messages of my own to decode. If you're confused about any part of it, ask away in the comments below! Binaries available on request.
#MORSE DECODER JAVASCRIPT FULL#
I have uploaded the full program to a repository on my personal git server, which you can find here: sbrl/AudioMorseDecoder. While the remainder of the algorithm is not too long (only ~202 lines), it's a bit too long to explain bit by bit here. Having drawn up an algorithm and 6 steps I needed to follow to create the program, I spent a happy afternoon writing some C♯. I appear to find it easy to break things down in my head - it's only when it gets too big to remember all at once or if I'm working with someone else that I draw diagrams :P I, however, ended up drawing the diagram after Id finished writing the program. It's a pretty complicated problem when you first think about it, but breaking it down into steps as I did in the above diagram really helps in figuring out how you're going to tackle it.
#MORSE DECODER JAVASCRIPT CODE#
Analyse the contextual tokens to extract the morse code as a string.Convert the context-free tokens into ones that hold the starting point and length of the tones.Analyse the windowed buffer and extract context-free tokens that mark the start or end of a tone.Extracts the maximum value from the window each time and places it in the windowed buffer. Move a sliding-window along the raw buffer, with a width of 100 samples and sliding along 25 samples at a time.If there isn't enough space to hold it all at once, then we handle it in chunks. I came up with that I think is a rather ingenious design.

That was easy! The next challenge to tackle was considerably more challenging though: Read in the audio file and analyse the samples. Public static string TranslateText(IEnumerable morseSources)įoreach(string morseSource in morseSources) / Translates a list of morse-encoded words. String morseLetters = morseSource.Split(" ".ToCharArray()) įoreach(string morseLetter in morseLetters) Public static string TranslateWord(string morseSource) / Translates a string of space-separated morse code strings from morse code. Public static char TranslateLetter(string morseSource) / Translates a single letter from morse code. Public static Dictionary morseCodeLookup = new Dictionary() / rather than accessing this lookup table directly! Use the methods in this class is possible, / A simple class to translate a morse code string into a normal string.

With a handy-dandy conversion chart, it was relatively simple to create a class to handle the conversion from dots and dashes to the latin alphabet automatically: using System decided to work in reverse, so the first thing I needed was a chart that converted morse code into the latin alphabet. After some digging, I discovered that NAudio is actually really powerful! It's got some pretty advanced functions for handling audio that I'll have to explore at a later date.Īnyway, with a plan of action I set to work. Amidst issues with flatpak and Monodevelop (flatpak is terrible!), I eventually found the NAudio ( Codeplex, GitHub, NuGet) package to do the job.
#MORSE DECODER JAVASCRIPT HOW TO#
Second problem: Figure out how to read the recording in and extract the samples in C♯. This was easy - the audio-recorder package in the ubuntu repositories solved that one easily, as it has an option to record the audio output of my laptop. My first problem: Capture a recording of the target morse code. Naturally, as a computer science student and enthusiast, I chose the second option. It said that the sender had hidden the message, so I was presented with 2 options: I could sit and decode the message by listening to it over and over again, or write a program to do it for me. Recently I received a message in morse code from a family member using this site. Weekend Challenge: Detecting and Decoding Morse Code in an Audio File
