2024-02-27 20:22:25

Hello, I have two questions about pyaudio.
1. Can I set the input stream's volume without affecting the system's global microphone volume setting? So like teamtalks microphone gain setting where you can control microphone volume without changing it from the control pannel. I looked pyaudio's functions, but didn't came across such function.
2. I want to add input device selection support to my project, but pyaudio shows duplicates of the same devices. Why this could be? I run this code
import pyaudio

p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
    device_info = p.get_device_info_by_index(i)
    device_name_lower = device_info['name'].lower()
    print(f"{device_info['name']} - Channels: {device_info['maxInputChannels']} input, {device_info['maxOutputChannels']} output")
And here's what I get (the some device names are in turkish)
Microsoft Sound Mapper - Input - Channels: 2 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High D - Channels: 2 input, 0 output
Mikrofon (Realtek High Definiti - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Microsoft Sound Mapper - Output - Channels: 0 input, 2 output
Hoparl├Âr (Realtek High Definiti - Channels: 0 input, 2 output
Birincil Ses Yakalama S├╝r├╝c├╝s├╝ - Channels: 2 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Birincil Ses S├╝r├╝c├╝s├╝ - Channels: 0 input, 2 output
Hoparl├Âr (Realtek High Definition Audio) - Channels: 0 input, 2 output
Hoparl├Âr (Realtek High Definition Audio) - Channels: 0 input, 2 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Speakers (Realtek HD Audio output) - Channels: 0 input, 2 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek HD Audio Stereo input) - Channels: 2 input, 0 output
Mikrofon (Realtek HD Audio Mic input) - Channels: 2 input, 0 output
Microphone (WO Mic Wave) - Channels: 1 input, 0 output
And the weird thing is some duplicates have incomplete names like realtek high definiti, but the other duplicates of the same defice have the complete name realtek high definition audio.
And If I try to open a stream with the duplicate devices, it doesn't work, only the first instance of each device work. For example, for the realtek microphone, only the first instance with the incomplete name realtek high definiti work. How can I fix this issue? so my code should only show 1 instance of each device, as I will present the user with a menu so they can choose what device they want to use.

Everything about people can change, including their appearance, but the character inside a person never changes.
Regards...

Bilal

2024-02-27 21:56:42

Idk pyaudio but your list there looks a lot like it is returning both input and output devices and you probably just need to figure out how to check which kind of device it is before assuming you can use it.

My Blog
Twitter: @ajhicks1992

2024-02-28 11:33:42

No, it shows duplicates of the same input device also, now I made it so it only shows input devices excluding output devices, and here's the output
Microsoft Sound Mapper - Input - Channels: 2 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High D - Channels: 2 input, 0 output
Mikrofon (Realtek High Definiti - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Birincil Ses Yakalama S├╝r├╝c├╝s├╝ - Channels: 2 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (WO Mic Device) - Channels: 1 input, 0 output
Stereo Kar─▒┼ş─▒m─▒ (Realtek HD Audio Stereo input) - Channels: 2 input, 0 output
Mikrofon (Realtek HD Audio Mic input) - Channels: 2 input, 0 output
Microphone (WO Mic Wave) - Channels: 1 input, 0 output
So, for the realtek microphone, there are 4 duplicates, its the same also for WOMic and stereo mix.
And for you I extracted the duplicates, here are the duplicates of realtek microphone
Mikrofon (Realtek High Definiti - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek High Definition Audio) - Channels: 2 input, 0 output
Mikrofon (Realtek HD Audio Mic input) - Channels: 2 input, 0 output
As you can see, the first duplicate has an incomplete name, realtek high definiti, and if I try opening a stream with other than the first duplicate of each device, it doesn't work. And each device has absolutely 4 duplicate, that's what I noticed now. Also, there is even two duplicates for using the default input device, microsoft mapper and Birincil Ses Yakalama S├╝r├╝c├╝s├╝, which translates to primary audio capture driver in english, but both actualy target the default input device on the system.

camlorn wrote:

Idk pyaudio but your list there looks a lot like it is returning both input and output devices and you probably just need to figure out how to check which kind of device it is before assuming you can use it.

Everything about people can change, including their appearance, but the character inside a person never changes.
Regards...

Bilal

2024-02-28 17:52:22

Well, I dunno.  Not sure anyone else here does or they'd have chimed in by now but maybe someone will show up eventually.  Truncated names is sorta fine.  I've seen that from time to time with various audio things.  Duplicated, I dunno at all unless it's trying to enumerate all backends or something and picking the wrong one.  You might have to open a bug or something.  You could see if the C/C++ Portaudio codebase it's binding has example programs and run them and see if it's broken in Python or Portaudio I suppose.

As I said in the other thread people don't do audio synthesis in Python.  Not sure what else you could be trying to do with it here and if there's something else ignore me, but if you are hoping to get anything even close to low latency audio while generating the samples in Python from Opus or whatever it will not happen anyway.  The heavy lifting for low-latency audio has to happen in a native language preferably without a gc.

My Blog
Twitter: @ajhicks1992

2024-02-28 20:14:58

Select the second device. You could exclude the first one if you wish to make it easier

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2024-02-29 10:40:27

I now found why it shows duplicates, because it was querying device list from both wasapi, dsound, waveout and wddmks at the same time which are 4 apis, and remember that my list had 4 duplicates for each device. And I had to filter the output, to remove duplicates, like this
import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
    device_info = p.get_device_info_by_index(i)
    device_name_lower = device_info['name'].lower()
    if device_info["hostApi"]==0 and device_info['maxInputChannels']>0: print(f"{device_info['name']} - Channels: {device_info['maxInputChannels']} input, {device_info['maxOutputChannels']} output")
for example this only shows waveout devices

Everything about people can change, including their appearance, but the character inside a person never changes.
Regards...

Bilal

2024-02-29 21:08:11

Note that you (probably) want wasapi devices.  WaveOut is an old deprecated API which is quite latent because they moved it to a compatibility layer in Vista. Same for DirectSound.  WaveOut these days is easily a 50-100ms penalty on top of all the other issues in front of you.

My Blog
Twitter: @ajhicks1992