jscwlib is a JavaScript library that generates Morse code (sound and optional graphical output) in the browser. It can easily be embedded in websites. It is developed for LCWO, but since it may be very useful for other purposes, it's available as a separate library.
jscwlib works with current versions of Firefox, Chrome, Edge, Opera and Safari, using the Web Audio API. For browsers that do not support the Web Audio API (like the Internet Explorer), there's a fall-back to the Embed Audio element.
<!DOCTYPE html> <script src="https://fkurz.net/ham/jscwlib/src/jscwlib.js"></script> <div id="player"></div> <script> var m = new jscw({"wpm": 25}); m.setText("hello cześć привіт <do>おはよう<sn>"); m.renderPlayer('player', m); </script>
Note that browsers typically only play sound if it was created by a keyboard/mouse/touch event, therefore the need to press a button to start it.
Live examples: Minimum example (above), Pileup, Oscilloscope, visualisation of CW timing .
params
is an optional object containing initial
settings corresponding to the variables that you can later also set by
the methods listed below.var m = new jscw({"wpm": 40,
"freq": 700, "text": "Hello"});
x
words per minute.x
words per minute. If it's equal, higher than
the character speed or zero, this parameter is ignored. Otherwise the spaces between
the characters are stretched to achieve the effective speed with a higher
character speed.x
Hertz.f
Hz.q
.text
to be played. Does not start playing yet. Text may
contain Latin, Cyrillic, Arabic, Hebrew, Greek or Japanese characters. Additional character sets can easily be
implemented.setText
, but the text has to be base64 encoded.v
(0 .. 100).text
(if not set: the last text set by play
or setText
in Morse code, with the parameters currently set. The
text may contain commands to change parameters on the fly:
|wXX
sets the character speed to XX
WpM,|eXX
sets the effective speed to XX
WpM,|WXX
sets the extra word space to XX
,|fXXX
sets the tone frequency to XXX
Hz,|vX
sets the volume to X
(0.0 - 1.0),|SXXXX
inserts a silence period of XXXX
milliseconds.<SK>
will generate
...-.-
s
seconds, after play() is invoked.p
. Each transmission is
prefixed with this string (e.g. VVV =
), but it does not influence
the calculation of speed.s
. Each transmission is
suffixed refixed with this string (e.g. +
), but it does not influence
the calculation of speed.c
).obj
into a div
.c
.m.onParamChange = function () { alert("Parameters changed"); }
m.onPlay = function () { alert("Player started"); }
m.onFinished = function () { alert("Player stopped"); }
m.onCharacterPlay = function (c) { console.log(c); }
The latest version of the library can be found in the git repository: https://git.fkurz.net/dj1yfk/jscwlib/. It is published under the very liberal MIT license.
You may directly embed the library into your own site by hot-linking to https://fkurz.net/ham/jscwlib/releases/jscwlib-0.2.2.js
jscwlib was written by Fabian Kurz, DJ5CW <fabian@fkurz.net>.
Here are a few real life examples where jscwlib is or can be used: