import MorseAdaptiveDecoder from 'morse-pro/src/morse-pro-decoder-adaptive.js'
MorseAdaptiveDecoder
Extends:
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 |
bufferSize: * |
|
public |
ditLen: * |
|
public |
ditLengths: *[] |
|
public |
fditLen: * |
|
public |
fditLengths: *[] |
|
public |
|
Method Summary
Private Methods | ||
private |
_addDecode(duration: *, character: *) |
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 |
From class MorseDecoder | ||
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 get |
ditLen: * |
|
public set |
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 |
Get the millisecond timings of all durations determined to be dits |
|
public get |
fditLen: * |
|
public set |
Set the length of a Farnsworth dit the decoder will look for. |
|
public get |
|
|
public get |
Get the millisecond timings of all durations determined to be spaces |
|
public |
characters: *[] |
|
public |
|
|
public |
|
|
public |
|
|
public |
timings: *[] |
|
public |
unusedTimes: *[] |
|
private |
|
|
private |
_fditLen: * |
|
private |
|
|
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 |
_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. |
Public Constructors
public constructor(params: Object, bufferSize: number) source
Constructor
Override:
MorseDecoder#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'. |
|
bufferSize | number |
|
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#ditLenpublic 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#fditLenpublic fditLengths: *[] source
Private Methods
private _addDecode(duration: *, character: *) source
Store the timing and the corresponding decoded character element.
Override:
MorseDecoder#_addDecodeParams:
Name | Type | Attribute | Description |
duration | * | ||
character | * |