Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Last active December 14, 2015 20:19
Show Gist options
  • Save jugglinmike/5143417 to your computer and use it in GitHub Desktop.
Save jugglinmike/5143417 to your computer and use it in GitHub Desktop.
A script to expand acronyms in text to their phonetic equivalents
// phonetic.js
// A script to expand acronyms in text to their phonetic equivalents
var defaultInput = "I am the illest MC that you ever SAW";
var sounds = {
A: "ay",
B: "bee",
C: "see",
D: "dee",
E: "ee",
F: "eff",
G: "jee",
H: "aych",
I: "I",
J: "jay",
K: "kay",
L: "el",
M: "em",
N: "en",
O: "O",
P: "pee",
Q: "cue",
R: "ar",
S: "ess",
T: "tee",
U: "you",
V: "vee",
W: "double you",
X: "ex",
Y: "why",
Z: "zee"
};
var input = process.argv.slice(2).join(" ") || defaultInput;
var expanded;
expanded = input.replace(/\b[A-Z]{2,}\b/g, function(letters) {
return letters.split("").map(function(letter) {
return sounds[letter];
}).join(" ");
});
console.log(expanded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment