morse-code-audio-generator
v1.1.0
Published
Text to Morse code and text to morse code audio generator
Readme
Morse Code Audio Generator
A Node.js package to:
- Convert Text → Morse Code
- Convert Morse Code → Text
- Generate Morse code audio (.wav) from text using sine wave synthesis
Features
- Encode plain text into Morse code
- Decode Morse code back into text
- Generate Morse code audio as
.wav - Pure JavaScript implementation
- No external audio processing tools required
Installation
npm install morse-code-audio-generatorNote : Requires Node.js 14 or above.
Usage
Import the package:
const morse = require("morse-code-audio-generator");Encode Text to Morse
console.log(morse.encode("SOS"));Output:
... --- ...Decode Morse to Text
console.log(morse.decode("... --- ..."));Output:
SOSGenerate Audio
morse.texttoAudio("HELLO", "hello.wav");This creates:
hello.wavThe generated file contains Morse code beeps.
Supported Characters
Alphabets
- A-Z
Numbers
- 0-9
Symbols
.,?!- Space (
)
Morse Timing Rules
- Dot (
.) → 100 ms beep - Dash (
-) → 300 ms beep - Symbol gap → 50 ms silence
- Letter gap → 150 ms silence
- Word gap → 500 ms silence
How Audio Generation Works
This package generates sound mathematically using a sine wave:
Math.sin(2 * Math.PI * frequency * time)Audio synthesis steps:
- Convert text into Morse code
- Convert dots/dashes into tones
- Generate raw PCM samples
- Save samples into a WAV file
Example
Input:
HELLO WORLDEncoded Morse:
.... . .-.. .-.. --- / .-- --- .-. .-.. -..Generated output:
hello.wavAPI
encode(text)
Returns Morse code string.
Example:
morse.encode("HELLO")decode(morse)
Returns decoded text.
Example:
morse.decode(".... . .-.. .-.. ---")texttoAudio(text, filename)
Generates .wav audio file.
Example:
morse.texttoAudio("SOS", "sos.wav")Author
Yash Kumar
License
ISC
