DEV Community

Cover image for Why I let strangers control my lights and why you should too
nobody5050
nobody5050

Posted on • Edited on

Why I let strangers control my lights and why you should too

The title photo features the website I built to let strangers annoy me. The website includes text to speech, YouTube audio playing, and even control of my lights. But why did I make it?

Why did I make it?

Well like many projects, this one was started over pure boredom from being on a break from school.

I’d had the idea for a while to try and replicate the tts setup twitch streamers use sometimes, but I wanted something unique, so I also added light controls.

Ok, that’s great and all, but how does it work?

The project actually has two parts, the tts part and the light control part.

first, how do the lights work?

The light controls are incredibly simple, I use LIFX http api to toggle the lights.

Below is a simple fetch api request to toggle some lights using default parameters, just replace YOUR-APP-TOKEN with the token lifx gives you.

So how does the text to speech work?

This is where the project gets considerably more complex. Fist up, discord webhooks.

When I was building the project I needed a way to store messages in a log, so I could read them if I’d been away from my loudspeaker or if it had turned off for some reason. The best one I can come up with is a discord webhook, it’s great because it acts as an intermediary between the site and my servers, as well as being completely free.

So how do you connect with it?

Below is the actual code I use for handling discord messages, including my webhook url

I opted to use xmlhttprequest here, since I’m more familiar with it, but you could use fetch as well.

The basic concept is this, it takes in text from a textbox element when the function sendMessage is called, then it sends that test as a request to whatever webhook url you specify.

Next up on the train, discord bots!

For handling the text to speech I use a python discord bot and the pyttsx3 library

I won’t show the code for this since it’s ugly and I don’t want people replicating it, but basically it watches for new messages in a discord channel, and then plays their contents through the pyttsx3 library using default parameters. I also run all requests through the googletrans python library to ensure that I hear all messages in my native tongue.

So why should you make it yourself?

Well I’ve been asked a fair bit by the people on my subreddit r/theannoyingmachine why I would build this, all I can say is that it’s more fun than it seems like!

If you’re interest in learning about api’s, webdevelopment, and python all in one project, you should do this one!

Thanks for reading my post!

The website featured in the post is https://nobody5050.GitHub.io/annoy

Top comments (17)

Collapse
 
trusktr profile image
Joe Pea

Would be sweet if you can add a camera feed so we can see the results!! :D

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal • Edited

Please, please, don't use XMLHttpRequest, instead use fetch, more mordern and prevents the callback hell

Collapse
 
nobody5050 profile image
nobody5050

Hey thanks for the comment, I chose xmlhttprequest for the discord code because I was more comfortable with the api, but I plan to change it out for fetch in the future when I have more experience

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal

Yeah sure, its just that I get vibes when I see XMLHttpRequest.

Thread Thread
 
nobody5050 profile image
nobody5050

Understandable. Can you recommend some resources for learning fetch?

Collapse
 
beginnercoder17 profile image
BeginnerCoder17

It sounds so stupid at first but it's fascinating! lol

Collapse
 
nobody5050 profile image
nobody5050

Thanks!

Collapse
 
beginnercoder17 profile image
BeginnerCoder17

Sorry if it sounds mean but it awesome!

Thread Thread
 
nobody5050 profile image
nobody5050

Doesn’t sound mean at all!

Collapse
 
steingabriel profile image
Gabriel Stein • Edited

Cool, I have LIFX lights here too and I'm creating a simple control panel to control all the smarts things in one place. They offer a very simple to use API.
I believe you posted the Discord snippet twice though.

Thanks for sharing this!

Collapse
 
nobody5050 profile image
nobody5050

Glad I could help! The only issue I had with the lifx api is the ratelimit, so I might switch to the lan api since that has no ratelimit.

I don’t see the discord snippet twice, does it still show up twice if you reload the page?

Collapse
 
anishdoesdev profile image
Anish A

Hey you've leaked your Discord webhook url which can be used to raid the server that the webhook is in. Would consider sending requests through a backend than a client-side post request.

Collapse
 
nobody5050 profile image
nobody5050

I use the discord channel as the intermediary, the actual tts stuff is handled by a discord bot that isn’t reachable from the site without going through the discord channel.

Collapse
 
anishdoesdev profile image
Anish A

I can nab that url and start mass @ everyone'ing.

Thread Thread
 
nobody5050 profile image
nobody5050

It’s a private server with only me and the bot, have fun

Collapse
 
eduplessis profile image
Edouard Duplessis

Funny... I just saw your house on reddit 😄

Collapse
 
fr3fou profile image
fr3fou

it'd be cool if we could see a livestream of it happening :D