it always infuriates me when I cannot set a game’s audio output device aside from changing my system default. Is there a way to set the audio device Unity is playing to from script (using C#, native plugins or some other method) to enable players to choose a device other than their system default? I have not been able to find any Unity API methods to change the device, only the current configuration (see AudioSettings). Using basic C# I haven’t been able to find anything useful yet either. I would be very thankful for any hints on how to accomplish this.
Is it simply not possible to change the playback device Unity is using in any way? Games like Guild Wars 2 and programs like Media Player Classic can do it, then again that’s neither Unity nor C#. I’ve yet to discover any way to change the audio device Unity is using. All I ever find are references on how to change Window’s default audio device which is certainly not the behaviour I am looking for.
Are you talking about the ability to have a selection screen with the different devices for your users? I know portaudio and rtaudio both have that ability for listing the devices and setting them, but to be honest, I’m not sure unity exposes that. I too would be interested as I have multiple devices as well.
Yes, it’s exactly what I’m looking to do: something like a combobox containing all possible audio devices with the ability to select one to use for Unity audio output. I will look into portaudio and rtaudio, thanks for mentioning them. Maybe they can be incorporated into Unity as a plugin.
I need to list the audio output devices in Unity, and let the user chose which device Unity should use for audio output (i.e. NOT the default audio output device selected in Windows)
Worst case, I assume I have to write a C++ native plugin and do some Windows API calls, and hook that up to a Unity UI in C#.
I did some preliminary testing with the FMOD package I’m using in AudioStream ( link in my signature ) and it seems to be correctly playing the audio on an user selected device/output present in the system.
Note since Unity atm always outputs to system’s default device, it’s not possible to play on selected device (other than default) via AudioSource - meaning you’ll loose all capabilities of manipulating the sound such as changing volume, pitch, spatialization, effecting etc. from the Editor/scripts - it completely sidesteps the Unity audio system.
I’d have to also come up with some kind of Editor integration since for FMOD to report all devices/drivers the system has to be initialized first - - as a workaround the user might be able to choose the output device only in runtime for now.
Simple playback of a single file or a stream ( which was the package originally intended for ) should work without problems.
I’d have to allocate some time for this, but PM me if you are interested in testing and seeing whether things would work with your setup.
Nice @r618 !
I’m struggling to understand how to select and initialize audio devices with low level api within unity in c#. Do you have a little reference for that?
Hi,
so if anybody is interested the new version of AudioStream got approved on the store with the ability to use any available audio output present in the system (for non AudioSource audio/streams EDIT: can handle AudioSource now, too).
Maybe somebody will find it useful.
I’m on Unity 2018.2.12f1 and it finally works to change default audio device in windows from toolbar icon => sound output in unity changes to that device. I still don’t know API that does this, but I’m happy that this basic thing finally works (it didn’t use to)
Yes, Unity now properly responds to notifications about system default audio device changes
but note this is something rather different than the OP was about
does unity allow non-default device with current build? i could manually changing output in the new windows 10 mixer works, but once the app is restarted then it goes back to default device and had to be manually set again… this is very streamer unfriendly… it would be great if there is a way to make a select device in game option… :-\
sorry to warm this up once again in 2023, but we are currently facing a project in which we need to explicitely output audio using the earphone speakers on mobile devices - both Android and iOS.
Anybody having ideas/workarounds despite spending the effort to integrate AudioStream and/or FMOD?
Would be awesome to hear some experiences & thanks in advance
Unity uses the AVAudioSession class to interact with iOS’s audio session. The audio session controls the audio behavior of the app. To route the audio to the earpiece you would need to set the AVAudioSession’s category to AVAudioSessionCategoryPlayAndRecord with the AVAudioSessionCategoryOptionDefaultToSpeaker option. This is not directly accessible via Unity and would require a native plugin to make these settings.
For Android, I’ve been told that this could work if permissions are set correctly in your manifest: