DEV Community

TateLyman
TateLyman

Posted on

Morse Code Translator with Audio Playback — Built in JavaScript

I built a Morse code translator that converts text to dots and dashes — and plays the audio.

The Build

The encoding is straightforward — a lookup table mapping each character to its Morse pattern:

const MORSE = {
  A: ".-", B: "-...", C: "-.-.",
  // ... etc
};
Enter fullscreen mode Exit fullscreen mode

The audio part uses the Web Audio API:

const ctx = new AudioContext();
const osc = ctx.createOscillator();
osc.frequency.value = 600; // classic Morse tone
Enter fullscreen mode Exit fullscreen mode

Dots play for 60ms, dashes for 180ms (3x). Letter gaps are 180ms, word gaps 420ms.

Features

  • Encode text → Morse
  • Decode Morse → text
  • Audio playback at 600Hz
  • Full A-Z, 0-9, punctuation reference chart
  • Copy results

Try the Morse Code Translator

Related tools:

Full toolkit: devtools-site-delta.vercel.app

Top comments (0)