MorseDecoder
Direct Subclass:
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 |
Get the millisecond timings of all durations determined to be dahs |
|
public get |
|
|
public set |
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 |
Get the millisecond timings of all durations determined to be dits |
|
public set |
Set the length of a Farnsworth dit the decoder will look for. |
|
public get |
fditLen: * |
|
public |
|
|
public |
|
|
public |
|
|
public get |
|
|
public get |
Get the millisecond timings of all durations determined to be spaces |
|
public |
timings: *[] |
|
public |
unusedTimes: *[] |
Private Members | ||
private |
|
|
private |
_fditLen: * |
|
private |
|
Method Summary
Public Methods | ||
public |
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 |
Should be set to the Farnsworth WPM speed of the input sound. |
|
public |
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 |
_timings2morse(times: number[]): string Convert from millisecond timings to dots and dashes. |
Inherited Summary
From class Morse | ||
public |
dictionaries: * |
|
public |
dictionary: {...undefined: Object, ...dict: Object} |
|
public |
morse2textD: {} |
|
public |
options: * |
|
public |
text2morseD: {} |
|
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 |
Tidies text (upper case, trim, squash multiple spaces) |
|
public |
tokeniseMorse(morse: *): * |
|
public |
tokeniseRawText(text: String): * Splits text into words and letters |
|
public |
tokeniseText(text: String): * Tidies and then tokenises text |
|
private |
_addDictionary(dict: Object) Load in a dictionary. |
|
private |
_input2output(tokens: *, dict: *): * |
|
private |
|
From class MorseCW | ||
public get |
baseLength: number: * 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 |
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 |
_baseElement: * The element of the dictionary that the ratios are based off |
|
private |
_baseLength: * |
|
private |
_ditsInParis: * |
|
private |
_fwpm: * |
|
private |
_lengths: * |
|
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 |
Set the Farnsworth WPM speed. |
|
public |
setFWPMfromRatio(ratio: number) Set the Farnsworth WPM given ratio of fditlength / ditlength |
|
public |
setLength(element: *, length: *) |
|
public |
setRatio(element: *, ratio: *) |
|
public |
Set the WPM speed. |
|
public |
setWPMfromDitLen(ditLen: number) Set the WPM given dit length in ms |
|
public |
testFWPMmatchesRatio(): * |
|
public |
testWPMmatchesRatio(): * |
|
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#constructorParams:
Name | Type | Attribute | Description |
params | Object | dictionary of optional parameters. |
|
params.dictionary | string |
|
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
public get dahs: number[]: * source
Get the millisecond timings of all durations determined to be dahs
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
public get dits: number[]: * source
Get the millisecond timings of all durations determined to be dits
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 get spaceThreshold: * source
public get spaces: number[]: * source
Get the millisecond timings of all durations determined to be spaces
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
jsonData | * |
public setFWPM(fwpm: number) source
Should be set to the Farnsworth WPM speed of the input sound. The speedCallback is executed.
Override:
MorseCW#setFWPMParams:
Name | Type | Attribute | Description |
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#setWPMParams:
Name | Type | Attribute | Description |
wpm | number | Speed in words per minute. |
public speedCallback(jsonData: *) source
Params:
Name | Type | Attribute | Description |
jsonData | * |
Private Methods
private _addDecode(duration: number, character: string) source
Store the timing and the corresponding decoded character element.