Skip to content

Commit 926bfda

Browse files
committed
new article
1 parent 6aec6ea commit 926bfda

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed
328 KB
Loading

public/images/nato/alphabet.png

19 KB
Loading

public/images/nato/challenge-ex.png

55.4 KB
Loading

src/pages/blog/nato-alphabet.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
layout: "../../layouts/Blog.astro"
3+
title: "Learning the NATO phonetic alphabet with the Web Speech API"
4+
pubDate: "2024-12-29"
5+
subtitle: "who said that video games can't teach you anything?"
6+
tags: ["projects", "games"]
7+
author: "Andrew"
8+
bestof: false
9+
---
10+
11+
## Motivation
12+
13+
As I write this, it's winter break! I'm back home and, along with sleeping in and grinding leetcode, I've been catching up on my video game backlog. One of my favorites right now is a virtual reality flight simulator called [VTOL VR](https://store.steampowered.com/app/667970/VTOL_VR/) (named after the type of aircraft that can perform [the takeoff and landing maneuver](https://en.wikipedia.org/wiki/VTOL)).
14+
15+
<div
16+
style="
17+
max-width: 550px;
18+
margin: 0 auto;
19+
text-align: center;
20+
"
21+
>
22+
<img
23+
src="/images/nato/VTOLVR_JixB7h0JTJ.jpg"
24+
alt="An in-air T55 from VTOL VR."
25+
style="max-width: 80%; height: auto;"
26+
/>
27+
</div>
28+
29+
<p style="margin-top: 10px;">
30+
<i style="display: flex; justify-content: center; font-size: 0.95em;">An in-air T55 from VTOL VR.</i>
31+
</p>
32+
33+
There are multiplayer lobbies in the game where you're able to talk to other pilots/air traffic controllers on the radio frequency. And while the level of realism is nowhere near what other networks such as [VATSIM](https://vatsim.net/) attempt to maintain, it's not unheard of for radio communications to use some of the specialized jargon used in the aviation industry. One hallmark of this lingo is the use of the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet), which is a mapping of every letter and number in the Roman alphabet. This is used to differentiate between letters that could be confused over a low-quality signal, such as radio or telephone.
34+
35+
<div
36+
style="
37+
max-width: 550px;
38+
margin: 0 auto;
39+
text-align: center;
40+
"
41+
>
42+
<img
43+
src="/images/nato/alphabet.png"
44+
alt="NATO phonetic alphabet."
45+
style="max-width: 80%; height: auto;"
46+
/>
47+
</div>
48+
49+
<p style="margin-top: 10px;">
50+
<i style="display: flex; justify-content: center; font-size: 0.95em;">
51+
NATO phonetic alphabet.&nbsp;
52+
<a href="https://en.wikipedia.org/wiki/NATO_phonetic_alphabet">(Source)</a>
53+
</i>
54+
</p>
55+
56+
57+
For example, if you're talking to an air traffic controller, mistakenly interpreting an instruction to `hold short runway 23 at *P*` as `hold short runway 23 at *B*` could potentially put multiple aircraft in danger. Because of this, the NATO phonetic system requires that any spelling of letters is expanded into the corresponding word in the alphabet. An aircraft with the callsign `N123AB` would be pronounced as `NOVEMBER ONE TWO THREE ALPHA BRAVO`.
58+
59+
The issue is... I don't play aviation-related games with comms frequently enough to have proficiency with the alphabet. I'm lucky that VTOL includes the phoneticization of the callsign of your plane, because if they didn't, I would have _no clue_ on how to properly describe my aircraft to people on frequency.
60+
61+
Just for fun, though[^1], I'd still like to be proficient at interpreting the letters.
62+
63+
## The Website
64+
65+
...so, I made a website. I used Astro, just because it's what I'm most comfortable with when rapidly prototyping. The [primary page](https://github.com/AndrewDTR/learn-nato/blob/master/src/pages/index.astro) contains nothing more than a few labels and a button, but that's all I needed!
66+
67+
The site will give you a four letter character combination -- say, `JUFH`, for example. It'll then activate your microphone and listen to hear if you say the correct phoneticization (in this case, it would mark you correct if you said `JULIET UNIFORM FOXTROT HOTEL`). If you blank on what a specific letter stands for, there's a hint button that you can press to see what to pronounce.[^2] When you get it correct, there's a nice burst of confetti, and the site will prompt you to try another example.
68+
69+
<div
70+
style="
71+
max-width: 550px;
72+
margin: 0 auto;
73+
text-align: center;
74+
margin-bottom: 20px;
75+
"
76+
>
77+
<img
78+
src="/images/nato/challenge-ex.png"
79+
alt="A challenge example from the NATO phonetic alphabet website."
80+
style="max-width: 100%; height: auto;"
81+
/>
82+
</div>
83+
84+
The hardest part of this was the audio detection -- but that wasn't too bad! Nearly every browser (except for Firefox...[^3]) supports the Web Speech API, which allows you to easily transcribe and synthesize text. There's no backend (at least, none that I had to deal with, as `SpeechRecognition` is a native browser API). All I have to do is check if the user's browser supports it, and, if so, initialize a few basic parameters.
85+
86+
```js
87+
const SpeechRecognition =
88+
window.SpeechRecognition || window.webkitSpeechRecognition;
89+
90+
if (SpeechRecognition) {
91+
const speech = new SpeechRecognition();
92+
speech.lang = "en-US";
93+
speech.interimResults = false;
94+
speech.continuous = true;
95+
...
96+
```
97+
98+
The browser calls a `speech.onresult` event when the user is finished speaking, and... that's it! All the validation is simply comparing that input with the expected result (which I generate from a dictionary of the phoneticizations).
99+
100+
That's it! [Here's the link to the site, if you'd like to try it out](https://nato.amoses.dev/). It's [entirely open source](https://github.com/AndrewDTR/learn-nato), so feel free to peek around if you're curious about any of the implementation details.
101+
102+
[^1]: _And_ because I'd like to be able to listen to plane spotting/ATC breakdown videos without having to pause the video and interpret the letters being said...
103+
104+
[^2]: Notably, pressing the hint button doesn't automatically skip you -- it still requires that you say the correct answer. This was inspired by the design pattern of Duolingo, whose team definitely has more UX experience with language learning than I do!
105+
106+
[^3]: Firefox has speech _synthesis_, which is the portion of the Web Speech API that allows for text to speech. However, because the speech recognition aspect of the API relies on offloading the data to remote servers, Mozilla hasn't implemented support for it. The site can recognize this and displays a generic "...speech recognition is not supported in this browser" message.

src/scripts/tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ window.mobileCheck = function () {
2323

2424
tooltip.textContent = displayHostname;
2525
tooltip.style.display = "block";
26-
tooltip.style.left = event.pageX + 10 + "px";
27-
tooltip.style.top = event.pageY + 10 + "px";
26+
tooltip.style.left = event.pageX + 5 + "px";
27+
tooltip.style.top = event.pageY + 5 + "px";
2828
}
2929
}
3030
});

0 commit comments

Comments
 (0)