Inspiration
I am currently taking a networks class and I thought it would be fun to convert network traffic into music! However, I wanted to make something cute and easy to use so I went simple by using ping as a subroutine (as opposed to tcpdump or traceroute)
What it does
The web app uses Streamlit to render a simple to use and cute interface that generates a playable audio clip based off of the output for ping. It also features a basic musical staff/ledger lines to visualize the notes!
Under the hood, it uses Streamlit's api to get user input (destination and length). These variables are then passed to a ping subroutine (destination being the destination ip/DNS, and length being the number of times a destination is pinged). The ping output is then parsed for the latency values, which are converted to audible frequencies with some simple math. These frequencies are then appended to a "song" which is converted to a WAV file using streamlit's audio integration.
There is also a cli version available in github!
How I built it
I used python3 as the programming language. Streamlit made ui and user interaction extremely easy! I also used pydub to easily create audio frequencies More details about the actual guts of the project are in the above "what it does" section Most of my time was spent formatting text and deploying to Streamlit's cloud community
Challenges I ran into
Challenge 1: Messing with audio in python is fun but there are a lot of different libraries and some of them work for different use cases. In my case, I started using the simpleaudio library, but unfortunately it is incompatible with headless machines (servers). As streamlit's cloud community is based off of linux servers, this had to be completely replaced with another python audio library. simpleaudio was replaced with pydub. pydub was simpler to use and was compatible with servers. However, Something I didn't consider was how the browser would play the audio. Yes, pydub is compatible with headless applications, but it is still not able to forward that audio output to the client browser. So, I had to use Streamlit's audio api, which was not difficult.
Challenge 2: Deploying to Streamlit Cloud Community was certainly not as easy as writing it. I ran into many issues with dependencies and libraries, however I believe a majority of these issued were my own fault. This was when I realized I had to change my python audio library as well.
Accomplishments that I'm proud of
- It looks cute!!
- I also was able to make a project with a reasonable scope.
- It's easily accessible through Streamlit Cloud Community!
What I learned
- Streamlit
- Audio with python (pydub and simpleaudio)
- subprocesses in Python
- Creating simple web apps like this is not hard! (as long as you use libraries and tools to help you)
What's next for NoisyNetworks
There are some features that I think would be cool!
- Currently, the app only plays a "song" in c-major. It would be cool If I added other keys.
- I could also make the CLI version easily accessible
- It wouldn't be too hard to add a speed slider
- I could also add an option to save and replay audio sequences from previous instances (database/file storage)
Built With
- pydub
- python
- streamlit