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

MorseAdaptiveDecoder

Extends:

MorseMorseCWMorseDecoder → MorseAdaptiveDecoder

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

Example:

var messageCallback = function(data) {
    console.log(data);
};
var speedCallback = function(s) {
    console.log('Speed is now: ' + s.wpm + ' WPM');
};
var decoder = new MorseAdaptiveDecoder({messageCallback, speedCallback});
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, bufferSize: number)

Member Summary

Public Members
public
public

ditLen: *

public

ditLengths: *[]

public

fditLen: *

public
public

Method Summary

Private Methods
private

_addDecode(duration: *, character: *)

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

From class MorseDecoder
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 get

ditLen: *

public set

ditLen(dit: number)

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

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 get

fditLen: *

public set

fditLen(dit: number)

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

public get
public get

spaces: number[]: *

Get the millisecond timings of all durations determined to be spaces

public

characters: *[]

public
public
public
public

timings: *[]

public
private
private
private
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

_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.

Public Constructors

public constructor(params: Object, bufferSize: number) source

Constructor

Override:

MorseDecoder#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'.

bufferSize number
  • optional
  • default: 30

Size of the buffer to average over

Public Members

public bufferSize: * source

public ditLen: * source

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

Override:

MorseDecoder#ditLen

public ditLengths: *[] source

public fditLen: * source

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

Override:

MorseDecoder#fditLen

public fditLengths: *[] source

public lockSpeed: boolean source

Private Methods

private _addDecode(duration: *, character: *) source

Store the timing and the corresponding decoded character element.

Override:

MorseDecoder#_addDecode

Params:

NameTypeAttributeDescription
duration *
character *