Need to convert text to or from Morse code in your application? This guide covers everything you need to know about Morse code conversion via API, including the International Morse Code standard and implementation examples.
What is Morse Code?
Morse code is a method of encoding text characters using sequences of dots (.) and dashes (-). Developed by Samuel Morse and Alfred Vail in the 1830s, it was used for telegraph communication and remains relevant today in amateur radio and emergency signaling.
Example: SOS becomes ... --- ...
How Morse Code Works
Morse code uses a simple encoding:
Dots and Dashes
Each letter and number is represented by a unique combination of short signals (dots) and long signals (dashes).
Timing
In audio/visual Morse, a dash is three times as long as a dot. Spaces between letters and words are also timed.
Common Codes
SOS (... --- ...) is the most recognized distress signal. E (.) is the most common letter, represented by a single dot.
Using the Morse Code API
TinyFn provides a simple endpoint for Morse code conversion:
POST https://api.tinyfn.io/v1/convert/morse
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Hello World",
"mode": "encode"
}
{
"result": ".... . .-.. .-.. --- / .-- --- .-. .-.. -..",
"original": "Hello World",
"mode": "encode"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | Text or Morse code to convert (required) |
mode |
string | "encode" (text to Morse) or "decode" (Morse to text) |
Code Examples
JavaScript / Node.js
const response = await fetch('https://api.tinyfn.io/v1/convert/morse', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: 'SOS', mode: 'encode' })
});
const result = await response.json();
console.log(result.result); // "... --- ..."
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/convert/morse',
json={'text': 'SOS', 'mode': 'encode'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['result']) # "... --- ..."
cURL
curl -X POST "https://api.tinyfn.io/v1/convert/morse" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "SOS", "mode": "encode"}'
Common Use Cases
- Educational Apps: Teaching Morse code to new learners
- Amateur Radio: Tools for ham radio operators
- Games: Puzzle games and escape room applications
- Accessibility: Alternative communication methods
- Novelty: Fun text conversion for social media
Best Practices
- Use standard format: Dots (.), dashes (-), spaces for letter separation, slashes for words
- Handle case: Morse code is case-insensitive - normalize to uppercase
- Support audio: Consider adding audio playback for Morse code
- Validate input: Check for valid Morse characters when decoding
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-convert": {
"url": "https://api.tinyfn.io/mcp/convert/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all conversion tools available via MCP in our Conversion MCP Tools for AI Agents guide.
Try the Morse Code API
Get your free API key and start converting Morse code in seconds.
Get Free API Key