HACKER Q&A
📣 desertraven

Cross platform method for accessing system audio output?


I was hoping to create a desktop app that analyses the system audio output in real time. Eg. I can analyse audio coming from YouTube, or Spotify, or iTunes. Nothing nefarious, just visualisation.

I looked into Electron’s desktop capture, and it doesn’t work for mac. I also looked at Swift MacOS app, but I don’t think that’s possible without a seperate program called SoundFlower and I don’t think it can be packaged with the macOS app itself.

How might I go about creating a desktop app which can access the audio output feed of the host system?


  👤 eduardosasso Accepted Answer ✓
Not sure how clean you want the audio to be but in a project I’m working on I’m using the input microphone to analyze the audio to build a music visualizer. https://soundq.co

👤 blaerk
Portaudio may be applicable, it supports most platforms I think.

http://www.portaudio.com/


👤 brudgers
An oscilloscope reading the headphone jack might be the simplest thing that might work...unless the problem is underspecified.

👤 minhmeoke
Perhaps you could use either http://libsound.io/ which provides low-level APIs to access operating-system sound systems like Alsa, PulseAudio, PipeWire, and CoreAudio. Or https://python-sounddevice.readthedocs.io/en/0.4.4/ if you prefer Python.

Comparisons:

- https://github.com/andrewrk/libsoundio/wiki/libsoundio-vs-Po...

- https://github.com/andrewrk/libsoundio/wiki/libsoundio-vs-JU...

- https://github.com/andrewrk/libsoundio/wiki/libsoundio-vs-SD... SDL2 game library + SDLAudioIn (doesn't appear to support Mac though: http://burningsmell.org/sdl_audioin/)

On a related note, a friend created some visualizations of interesting sounds. If you'd like the source code (Python Jupyter notebooks), please let me know!

A few examples:

1. Dialtone using dual-tone multi-frequency signaling and 56K dial-up modem connection: https://www.youtube.com/watch?v=FomWraKuDFg&list=PLn67ccdhCs...

2. Deluxe Multitone Car Alarm: https://www.youtube.com/watch?v=A4uKcvZL7HM&list=PLn67ccdhCs...

3. Composition using only sounds from Windows 98 and XP https://www.youtube.com/watch?v=6lT-jr9sS6Y&list=PLn67ccdhCs...

4. Piano Music (Ballade Pour Adeline): https://www.youtube.com/watch?v=RnAfrEk429w&list=PLn67ccdhCs...

5. Electronic Music Demo: https://www.youtube.com/watch?v=MllJLIX1glg&list=PLn67ccdhCs...