Benjamin blog
  • Firebase cloud functions
  • Connect to aws database
  • connect-to-raspberry-pi-np-hdmi
  • Get your logs from your mobile to your desktop
  • Twitter bot
  • Crontab
  • Delete your git history
  • How I hacked my sons Duplo train to go faster using my voice
  • Finetune GTPT-3
  • Create a localhost tunnel
  • Paste clipboard to vim through ssh in Windows
  • Predictions of the future
  • Prisma
  • Connect to Raspberry Pi no HDMI output
Powered by GitBook
On this page
  • Research phase
  • Connecting to the train
  • Getting the pitch of someone's voice
  • Gluing everything together
  • The final result 🚂

How I hacked my sons Duplo train to go faster using my voice

PreviousDelete your git historyNextFinetune GTPT-3

Last updated 2 years ago

So my son got a for his birthday. The train is fairly advanced. There are different blocks you put on the tracks that make it do different actions: one will make the train turn on the light, one will reverse the driving direction of the train, one will make the train play a specific sound and one will make the train stop.

On top of that you can control the train with (because of course). In the app you can control the speed, different sounds, the lights and the driving direction. The app connects to the train via Bluetooth and that gave me an idea 💡

What if you could control the train using your voice? Wouldn't that be cool!? 😎

Research phase

Now I had to research if someone had tried something similar. That led me to a Dutch guy that had , where the train made sounds and drove around based on some events on his own alt coin.

The for controlling the train was linked in his article, and that script led me to - A Javascript module to interface with LEGO Powered Up components. Apparently LEGO has made lots of that can be controlled via Bluetooth of which the Duplo train was one of them.

✅ Was it possible to control the train - yes

Connecting to the train

Now I knew it was possible to control the train, but could I make it work?

My first stab at it was on my Windows machine. I started developing a bit too quick (story of my life) without checking the . This gave me a lot of problems. When I finally found the prerequisites I saw that it was a lot easier using a Mac compared to Windows.

So I booted up my work computer and quickly got a successful connection. Yeah 🥳

The script that the Dutch guy had made was outdated though. The entire node-poweredup api had changed so into the I dove 🏊‍♀️

It took a bit of time but I finally made the train drive and quickly learned to debug the train by putting it on its side. My arm was getting a bit tired after constantly moving the train back and forth.

✅ Could I control the train - yes

Getting the pitch of someone's voice

On to the next problem: Figuring out if I could get the pitch of someone's voice.

But the connection to the train was made in nodejs. Therefore I had to do the pitch detection in nodejs. This proved to be a huge problem 🤔 I am still not really sure if it is possible. I tried out a few libraries but didn't really get anything working.

const [pitch, clarity] = detector.findPitch(input, sampleRate);

Now all I needed to do was to send the pitch to nodejs.

✅ Could I detect the pitch in someone's voice - yes

Gluing everything together

The final result 🚂

I knew this was possible. I had made a in python where clapping would start playing some music. This was done using a technique called where you transform the audio signal into its frequency domain.

Then I tried to approach it from another angle 🔎 What if I instead detected the pitch in the browser? Luckily there was a great library called that solved this exact problem. Look at this simple, magnificent api with a 👌

All I had left from here was to glue everything together by sending the pitch to nodejs and then using that pitch to control the speed of the train. That was done using . Socket.io lets you send data bidirectionally in real time. So from the client to the server and from the server to the client.

Luckily I had also worked with Socket.io before while building an , so it did not take too long to get it working.

The last tweaking was done around , how to and so that the train will only drive when someone is saying something.

You can see the final result here:

If you want to try it out for yourself, feel free; The code can be found . Just remember the !

Checkout if you like these kinds of projects

Duplo train
an app
put his sons duplo train on the blockchain
script
node-poweredup
components
prerequisites
documentation
previous project
fft
Pitchy
great, clear example
Socket.io
online slime volley game
how often to send the pitch
map the pitch to a train speed
filtering the signal
I hacked my sons Duplo train 🚂💻
here
prerequisites
my portfolio