ardaku / wavy

Asynchronous cross-platform real-time audio recording & playback.
https://docs.rs/crate/wavy/latest
Apache License 2.0
84 stars 4 forks source link

[Question] Linux: USB-Audio Card #16

Closed pvitaliy84 closed 3 years ago

pvitaliy84 commented 3 years ago

How to choose external USB-audio card for record?

AldaronLau commented 3 years ago

@pvitaliy84 Currently, wavy connects to the default ALSA configuration. If you're running pulseaudio you should be able to select your external audio card in pavucontrol, and set it as the default card (you do this by setting other audio cards to "fallback"). You can also do it in gnome-settings if you're on gnome (which is a bit easier). Otherwise, you'll have to mess with the ALSA config files.

Eventually (hopefully soon), I plan to add an API which you can use to build an interface to select the audio card you want to use. I actually need this feature for a side-project, so I might try to set aside some time for it in the near future.

AldaronLau commented 3 years ago

You can now do (in wavy 0.6.0):

use wavy::MicrophoneId;

let microphones = MicrophoneId::query();
for (id, microphone) in microphones.iter().enumerate() {
    println!("[{}] {}", id, microphone);
}

// Prompt the user to select a microphone by ID, or hardcode it
...

let microphone = microphones[user_chosen_id].connect::<ChosenAudioFormat>().expect("Microphone unplugged");

// Record audio (same API as before)
...
pvitaliy84 commented 3 years ago

Very cool! I will try it in evening.

And another question: how to stop record/play?

AldaronLau commented 3 years ago

If you want the microphone to stop, you can put it in an Option and set it to None. When you want it start again you can reconnect and set the variable to Some.