Home Reference Source Repository
import MorseDecoder from 'morse-pro/src/morse-pro-decoder.js'
public class | source

MorseDecoder

Extends:

MorseMorseCW → MorseDecoder

Direct Subclass:

MorseAdaptiveDecoder

Class to convert from timings to Morse code. Uses "international" dictionary.

Example:

// The messageCallback is called when a character or more is decoded
// It receives a dictionary of the timings, morse, and the message
var messageCallback = function(data) {
    console.log("Decoded: {\n  timings: " + data.timings + "\n  morse: " + data.morse + "\n  message: " + data.message + "\n}");
}
var wpm = 10;
var decoder = new MorseDecoder({wpm, messageCallback});
var t;
while (decoder_is_operating) {
    // get some ms timing "t" from a sensor, make it +ve for noise and -ve for silence
    decoder.addTiming(t);
}
decoder.flush();  // make sure all the data is pushed through the decoder

Constructor Summary

Public Constructor
public

constructor(params: Object)

Constructor

Member Summary

Public Members
public

characters: *[]

public get

Get the millisecond timings of all durations determined to be dah-spaces

public get

dahs: number[]: *

Get the millisecond timings of all durations determined to be dahs

public get
public set

ditLen(dit: number)

Set the length of a dit the decoder will look for.

public get

ditLen: *

public get

Get the millisecond timings of all durations determined to be dit-spaces

public get

dits: number[]: *

Get the millisecond timings of all durations determined to be dits

public set

fditLen(dit: number)

Set the length of a Farnsworth dit the decoder will look for.

public get

fditLen: *

public
public
public
public get
public get

spaces: number[]: *

Get the millisecond timings of all durations determined to be spaces

public

timings: *[]

public
Private Members
private
private
private

Method Summary

Public Methods
public

addTiming(duration: number)

Add a timing in ms to the list of recorded timings.

public

flush()

Process the buffer of unused timings, converting them into Morse and converting the generated Morse into a message.

public

messageCallback(jsonData: *)

public

setFWPM(fwpm: number)

Should be set to the Farnsworth WPM speed of the input sound.

public

setWPM(wpm: number)

Should be set to the WPM speed of the input sound.

public

speedCallback(jsonData: *)

Private Methods
private

_addDecode(duration: number, character: string)

Store the timing and the corresponding decoded character element.

private
private

_getTimings(character: *): number[]

Get a list of all the timings that were interpreted to be a particular character

private

Convert from millisecond timings to dots and dashes.

Inherited Summary

From class Morse
public
public

dictionary: {...undefined: Object, ...dict: Object}

public
public

options: *

public
public

display(tokens: Array, charSpace: String, wordSpace: String, map: Map, errors: Array, errorPrefix: String, errorSuffix: String): *

General method for converting a set of tokens to a displayable string

public

displayMorse(morseTokens: *): *

public

displayMorseErrors(morseTokens: *, errorTokens: *, prefix: *, suffix: *): *

public

displayText(textTokens: Array, escapeMap: Map): *

Convert from text tokens to displayable String

public

displayTextErrors(textTokens: *, escapeMap: *, errorTokens: *, prefix: *, suffix: *): *

public

looksLikeMorse(input: *): *

public

morse2text(morse: *): *

public

morseTokens2text(morseTokens: *): {"morse": *, "text": *, "error": *, "hasError": *}

public

setDictionaries(dictList: List)

Set the list of dictionaries to use.

public

setDictionariesAndOptions(dictList: *, optionList: *)

public

setOptions(optionList: List)

Set the list of dictionary options to use.

public

text2morse(text: *): *

public

text2morseClean(text: *): *

public

textTokens2morse(textTokens: Array): *

public

tidyText(text: String): *

Tidies text (upper case, trim, squash multiple spaces)

public

tokeniseMorse(morse: *): *

public

Splits text into words and letters

public

tokeniseText(text: String): *

Tidies and then tokenises text

private

Load in a dictionary.

private

_input2output(tokens: *, dict: *): *

private
From class MorseCW
public get

Get the length of the base element (i.e.

public get

Get the Farnsworth dit length to dit length ratio

public get
public get

lengths: *: *

Calculate and return the millisecond duration of each element, using negative durations for spaces.

public get

Return the length of the longest beep in milliseconds.

public get
public set

ratios(r: Map)

Set the ratio of each element and normalise to the base element/ For the space elements, the ratio is negative.

public get

Get the absolute duration of the space between words in ms.

public get
private

The element of the dictionary that the ratios are based off

private
private
private

_fwpm: *

private
private
private

_ratios: *

private
private

_wpm: *

public

getDuration(timings: Array): *

Add up all the millisecond timings in a list

public

morseTokens2timing(morseTokens: Array, lengths: Object): number[]

Return an array of millisecond timings.

public

setFWPM(fwpm: number): *

Set the Farnsworth WPM speed.

public

Set the Farnsworth WPM given ratio of fditlength / ditlength

public

setLength(element: *, length: *)

public

setRatio(element: *, ratio: *)

public

setWPM(wpm: number): *

Set the WPM speed.

public

Set the WPM given dit length in ms

public
public
private

Force the FWPM to match the fditlen/ditlen ratio without changing anything else

private

Force the WPM to match the base length without changing anything else

Public Constructors

public constructor(params: Object) source

Constructor

Override:

MorseCW#constructor

Params:

NameTypeAttributeDescription
params Object

dictionary of optional parameters.

params.dictionary string
  • optional
  • default: 'international'

optional dictionary to use. Must have same timing as 'international'.

params.dictionaryOptions string[]

optional additional dictionaries such as 'prosigns'.

params.wpm number

speed in words per minute using "PARIS " as the standard word.

params.fwpm number

farnsworth speed.

params.messageCallback function()

Callback executed with {message: string, timings: number[], morse: string} when decoder buffer is flushed (every character).

params.speedCallback function()

Callback executed with {wpm: number, fwpm: number} if the wpm or fwpm speed changes. The speed in this class doesn't change by itself, but e.g. the fwpm can change if wpm is changed. Returned dictionary has keys 'fwpm' and 'wpm'.

Public Members

public characters: *[] source

public get dahSpaces: number[]: * source

Get the millisecond timings of all durations determined to be dah-spaces

Return:

number[]

public get dahs: number[]: * source

Get the millisecond timings of all durations determined to be dahs

Return:

number[]

public get ditDahThreshold: * source

public set ditLen(dit: number) source

Set the length of a dit the decoder will look for. Updates wpm and fwpm.

public get ditLen: * source

public get ditSpaces: number[]: * source

Get the millisecond timings of all durations determined to be dit-spaces

Return:

number[]

public get dits: number[]: * source

Get the millisecond timings of all durations determined to be dits

Return:

number[]

public set fditLen(dit: number) source

Set the length of a Farnsworth dit the decoder will look for. Updates ditLen (ensuring ditLen is not longer).

public get fditLen: * source

public message: string source

public morse: string source

public noiseThreshold: number source

public get spaceThreshold: * source

public get spaces: number[]: * source

Get the millisecond timings of all durations determined to be spaces

Return:

number[]

public timings: *[] source

public unusedTimes: *[] source

Private Members

private _ditDahThreshold: * source

private _fditLen: * source

private _spaceThreshold: * source

Public Methods

public addTiming(duration: number) source

Add a timing in ms to the list of recorded timings. The duration should be positive for a dit or dah and negative for a space. If the duration is <= noiseThreshold it is assumed to be noise and is added to the previous duration. If a duration is the same sign as the previous one then they are combined.

Params:

NameTypeAttributeDescription
duration number

millisecond duration to add, positive for a dit or dah, negative for a space

public flush() source

Process the buffer of unused timings, converting them into Morse and converting the generated Morse into a message. Should be called only when a character space has been reached (or the message is at an end). Will call the messageCallback with the latest timings, morse (dots and dashes) and message.

public messageCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

public setFWPM(fwpm: number) source

Should be set to the Farnsworth WPM speed of the input sound. The speedCallback is executed.

Override:

MorseCW#setFWPM

Params:

NameTypeAttributeDescription
fwpm number

Speed in words per minute.

public setWPM(wpm: number) source

Should be set to the WPM speed of the input sound. The speedCallback is executed.

Override:

MorseCW#setWPM

Params:

NameTypeAttributeDescription
wpm number

Speed in words per minute.

public speedCallback(jsonData: *) source

Params:

NameTypeAttributeDescription
jsonData *

Private Methods

private _addDecode(duration: number, character: string) source

Store the timing and the corresponding decoded character element.

Params:

NameTypeAttributeDescription
duration number

the millisecond duration (always +ve).

character string

the corresponding character element [.-/ ].

private _clearThresholds() source

private _getTimings(character: *): number[] source

Get a list of all the timings that were interpreted to be a particular character

Params:

NameTypeAttributeDescription
character *

Return:

number[]

private _timings2morse(times: number[]): string source

Convert from millisecond timings to dots and dashes.

Params:

NameTypeAttributeDescription
times number[]

array of millisecond timings, +ve numbers representing a signal, -ve representing a space.

Return:

string

the dots and dashes as a string.