How do I change audio input device using AudioServer.capture_set_device() ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By smilesAo

I am trying to change the audio input device using AudioServer.capture_set_device() but it always remains “default”

extends Node

func _ready() -> void:

func switch_mic()->void:
	var mic_list : Array = AudioServer.capture_get_device_list()
	for i in mic_list:

this prints:

[Default, Line (Elgato Sound Capture), Line (VB-Audio Virtual Cable), Mic in at front panel (Pink) (2- Realtek High Definition Audio), Desktop Microphone (2- Microsoft® LifeCam HD-3000), Microphone (Steam Streaming Microphone)]

the list of my audio input devices, but then it never changes from default. Is this a bug or am I doing something wrong?

I have the same exact problem :confused:

WilliamD47 | 2021-01-12 21:50

I have this issue too. Maybe a bug with capture_set_device() ?

chickynugs | 2021-01-15 19:31

I still have not found a solution to this issue. Is there a place to report bugs?

smilesAo | 2021-02-08 04:44

Yes on the Godot Github. Go to the Issues tab

WilliamD47 | 2021-02-08 14:18

I have found a potential fix. If you have an AudioStream that you are using to record, turning on autoplay is not sufficient. Godot only started listening to my mic when playing is true. Once I turned on playing, it started recording my mic, and AudioServer.capturesetdevice() worked. I believe this is because if the stream is not playing, the mic is not detected and the device is automatically set to default, as seen on the AudioServer docs.
“If an invalid device name is set, the value will be reverted back to “Default”.”

User1013483241 | 2022-12-03 23:42