- Home /
Getting Unity to listen to desktop audio
This probably doesn't have an easy solution, but I'm working on a music visualizer. Currently, it has some preloaded tracks is uses for the audio, but I'd like the app to be able to use any audio the user has playing on their computer. For example, they can run the app then go to Youtube and play any song they want. The app will listen to that audio. Essentially, I want the app to be able to use the desktop audio as the audio source. Is there an existing plugin I can use or some other method to do this? Preview of the project: https://www.youtube.com/watch?v=f-XGgs0jHl8
TLDR: How do I make Unity listen to the desktop audio and use it as the audio source? NOTE: I've been writing this program in C#.
EDIT: Looks like what I need specifically is to give Unity "WASAPI Loopback Capture," at least for Windows. It would be nice if I could get this to work on OSX as well, but it's a start.
https://github.com/filoe/cscore
This might be of some use.
Answer by hallidev · Oct 27, 2017 at 12:53 PM
I'm not sure where you ended up with this, but I've been playing around with a visualizer of my own, and I wanted the same thing.
I used the excellent CSCore library (https://github.com/filoe/cscore) to accomplish it. It's capable of visualizing "what you hear" (WASAPI Loopback Capture). I came across this while searching for a way to feed the raw audio data into a Unity AudioSource since I'm too lazy to write my own beat detectors and all of the Asset Store assets work off AudioSource. If you're just interested in spectrum data though, it works great. I don't have a problem sharing it with you.
If you're still interested, reply here and I'll put something together for you.
Edit: Since OP showed interest, here's a working example
Yeah, I'd love to see the code you used to accomplish this! To get the visualizer working I followed a tutoral by PeerPlay on Youtube. I'm not as code-savvy as I'd like to be so seeing examples really helps.
Sure thing. I'm at work now (slow day as you can see) but plan on playing with my visualizer tonight. I'll post a barebones example project to GitHub for you and anyone else interested. It should be a "get project loaded in Unity and press play to see it working" type thing.
I provided a link to a working example in my edit. Hope it's what you're looking for!
I have had the same challenge and your shared project is surely going to help a lot, thank you and cheers!
Hey mate tips for editing your Gihubtomake it more responsive? lag intervals admiss the projects,..
Answer by sonofbryce · Sep 14, 2017 at 11:04 PM
I think the asset "AudioStream" will allow you to do this: https://assetstore.unity.com/packages/tools/audio/audiostream-65411