Skip to content

Instantly share code, notes, and snippets.

@jsundram
Last active October 16, 2023 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/26b7435871fffdca3464856c8a75b845 to your computer and use it in GitHub Desktop.
Save jsundram/26b7435871fffdca3464856c8a75b845 to your computer and use it in GitHub Desktop.
Spell out a word (or string) in the Nato Alphabet, in an output format suitable for piping to the MacOS "say" command
import sys
# from https://www.worldometers.info/languages/nato-phonetic-alphabet/
TABLE = """
A Alfa/Alpha ● ▬ AL FAH
B Bravo ▬ ● ● ● BRAH VOH
C Charlie ▬ ● ▬ ● CHAR LEE
D Delta ▬ ● ● DELL TAH
E Echo .● ECK OH
F Foxtrot ● ● ▬ ● FOKS TROT
G Golf ▬ ▬ ● GOLF
H Hotel ● ● ● ● HOH TELL
I India ● ● IN DEE AH
J Juliett ● ▬ ▬ ▬ JEW LEE ETT
K Kilo ▬ ● ▬ KEY LOH
L Lima ● ▬ ● ● LEE MAH
M Mike ▬ ▬ MIKE
N November ▬ ● NO VEMBER
O Oscar ▬ ▬ ▬ OSS CAH
P Papa ● ▬ ▬ ● PAH PAH
Q Quebec ▬ ▬ ● ▬ KEH BECK
R Romeo ● ▬ ● ROW ME OH
S Sierra ● ● ● SEE AIRRAH
T Tango ▬ TANG OH
U Uniform ● ● ▬ YOU NEE FORM
V Victor ● ● ● ▬ VIK TAH
W Whiskey ● ▬ ▬ WISS KEY
X X-ray ▬ ● ● ▬ ECKS RAY
Y Yankee ▬ ▬ ● ● YANG KEY
Z Zulu ▬ ▬ ▬ ▬ ▬ ZOO LOO
"""
def get_table():
global TABLE
x = {}
rows = TABLE.split('\n')
for row in rows:
if row:
a, name, morse, pr = row.split('\t')
x[a] = name.split('/')[0]
return x
def main(s):
table = get_table()
# TODO: could use punctuation more effectively to get the mac `say` command
# to pause appropriately.
for c in s.upper():
if c in table:
print("%s as in %s." % (c, table[c]))
else:
print("%s;" % c)
if __name__ == '__main__':
# usage: python3 say.py "7SAYGDEF5PF870876" | say
# python3 say.py "7SAYGDEF5PF870876" | say -r 80
s = sys.argv[1]
main(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment