jscwlib - JavaScript Morse Code Library


Release v0.2.0. Added Japanese Wabun code (tnx JE1TRV). Allow changing frequency while playing. Implement command |W for extra word spacing. Some small bug fixes.
Release v0.1.0.
Website created. No release yet - very preliminary but working code in git.


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.

Example usage

Live Result
<!DOCTYPE html>
<script src="https://fkurz.net/ham/jscwlib/src/jscwlib.js"></script>

<div id="player"></div>    

  var m = new jscw({"wpm": 25});
  m.setText("hello cześć привет <do>おはよう<sn>");
  m.renderPlayer('player', m);

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 .


new jscw(params)
params is an optional object containing initial settings corresponding to the variables that you can later also set by the methods listed below.
Example: var m = new jscw({"wpm": 40, "freq": 700, "text": "Hello"});


Initialize the player (optional - will be called internally if not done by the user).
Sets the character speed to x words per minute.
Sets the effective speed to 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.
When true, generate code with real character speed, not PARIS timing.
Add extra word spacing of n × the normal word space.
Set the tone frequency to x Hertz.
Set the cutoff-frequency of the low-pass filter that shapes the generated tone to f Hz.
Set low-pass filter Q to q.
Set text to be played. Does not start playing yet. Text may contain latin or cyrillic characters. Additional character sets can easily be implemented.
Sets the volume to v (0 .. 100).
Plays 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: Furthermore, anything enclosed in angle brackets will be sent without letter spaces (like a prosign), for example <SK> will generate ...-.-
Pauses or resumes the current text.
Stops the current text.
Delays the actual text by s seconds, after play() is invoked.
Sets the transmission prefix to p. Each transmission is prefixed with this string (e.g. VVV = ), but it does not influence the calculation of speed.
Sets the transmission suffix to s. Each transmission is suffixed refixed with this string (e.g. +), but it does not influence the calculation of speed.
When set to true, enable the transmission of the prefix and suffix.
Get the total play time of the current text in seconds.
Get the remaining play time of the current text in seconds.
Get the current time within the played text in seconds.
Draws the last generated Morse code as a timing diagram on a HTML5 canvas (c).
renderPlayer(div, obj)
Renders a player UI (with progress bar and buttons for Stop, Play/Pause and the possibility to change CW parameters) for player obj into a div.
Draws the currently generated waveform on canvas c.


A user defined function that will be invoked each time the player is started. E.g.:
m.onPlay = function () { alert("Player started"); }

Download / Embedding

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.0.js


jscwlib was written by Fabian Kurz, DJ1YFK <fabian@fkurz.net>.

Last modified: Monday, 06-Jul-2020 16:41:36 CEST