Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microphone is not recognized when audio devices are set to Analog Stereo Duplex #48

Open
kevinbbbb opened this issue Jan 7, 2025 · 3 comments

Comments

@kevinbbbb
Copy link

Hey there,
I really enjoy using your program when I listen to radio and mixes on my laptop.
Unfortunately, after starting the program and initiating tagging with either SPACE or A, I often get the following error message:

@user: ~/Musik$ ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave                                                 
sox FAIL sox: Sorry, there is no default audio device configured
error: sox exited with code 1

Writing this Github issue, I think I finally figured out how to reproduce it on my laptop (Kubuntu 24.04 LTS). With no headphones etc. connected, my audio devices are configured as Analog Stereo Duplex, so both speakers (output) and microphone (input) are enabled.

grafik

With this settings, your Shazam program doesn't work reliably on my laptop. At the time of writing this, I always get the error message with this configuration.

However, when I switch the device settings to Analog Stereo Input, where only the microphone is enabled and speakers are shut off, it works perfectly fine (when I play music from my phone, as the laptop's speakers are disabled)!
When I switch to Analog Stereo Output (microphone off, speakers on) I get the identical error message as with Analog Stereo Duplex, which suggests that with Analog Stereo Duplex the Shazam program does not recognize the microphone properly.

I didn't notice this issue when I started using your program. The issue used to appear only rarely when I started using your Shazam program (mid November '24) but after maybe a month, I can rarely ever use it because this error message appears very frequently. I also don't know why it sometimes works and sometimes doesn't, I always have my audio devices set to Analog Stereo Duplex.

What doesn't (reliably) solve the problem:

  • restarting terminal and program
  • rebooting PC
  • back and forth switching of audio device settings
@AlekseyMartynov
Copy link
Owner

Hello,

The app internally launches the following command:

sox -q -d -r 16000 -c 1 -b 16 -e signed-integer -t raw OUTPUT

Feel free to debug it directly.

If you find that you need to set a specific capture device, you can use the standard AUDIODEV environment variable like this:

AUDIODEV=XX ./Shazam.linux-x64 

To list available device names, run:

arecord -l

@kevinbbbb
Copy link
Author

Thanks for coming back to me. I did some testing with a Bluetooth speaker and tried your proposal with changing the AUDIODEV variable.

More testing results:

I just used the Shazam app without issues, with some other device (e.g. a Bluetooth speaker) selected as output device. (Input device is unchanged and still Analog Stereo Duplex).

Image

Turning off Bluetooth forces a swith of output devices to Analog Stereo Duplex. Trying to tag with the app will only return an error now. Connecting to the BT speaker again, and instantly trying to tag will also return an error. But after a few seconds, tagging works without issues again.
I observed similar behaviour if I don't disconnect the BT speaker but just switch the output device back and forth.

In conclusion, the app seems to work reliably when an output device other then the internal speakers (Analog Stereo Duplex) are selected.

Trying to change AUDIODEV variable

When I try to list available devices with arecord -l, I get:

@user:~/Musik$ arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 0: PCH [HDA Intel PCH], Gerät 0: ALC236 Analog [ALC236 Analog]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0

If I understand correctly, it recognizes some device(s) (?). I replaced XX with PCH, HDA Intel PCH, ALC236 Analog, Karte 0 but these did not work. I am getting an error like Unknown PCM <XX>. Not sure what exactly PCM is but I guess I need to put the name of a PCM here.

Reading online, I found that PCMs can be listed with arecord -L. I ran that and got:

@user:~/Musik$ arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
lavrate
    Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
hw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC236 Analog
    Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC236 Analog
    Hardware device with all software conversions
default:CARD=PCH
    HDA Intel PCH, ALC236 Analog
    Default Audio Device
sysdefault:CARD=PCH
    HDA Intel PCH, ALC236 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC236 Analog
    Front output / input
dsnoop:CARD=PCH,DEV=0
    HDA Intel PCH, ALC236 Analog
    Direct sample snooping device
usbstream:CARD=PCH
    HDA Intel PCH
    USB Stream Output

(When I run arecord -l or arecord -L, I get the same result, whether the BT speaker is connected or not. I guess this should be expected since the commands refer to capture devices and these are the same in both cases.)

Now, I tried putting use some names of PCMs as AUDIODEV variable. I did not get tagging to work. The error messages were slightly different:

@user:~/Musik$ ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave                                                 
sox FAIL sox: Sorry, there is no default audio device configured
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=default:CARD=PCH ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave                                                 
sox FAIL sox: Sorry, there is no default audio device configured
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=sysdefault:CARD=PCH ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave                                                 
sox FAIL sox: Sorry, there is no default audio device configured
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=front ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... sox FAIL sox: Sorry, there is no default audio device configured                                                  
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=hw:CARD=PCH,DEV=0 ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... sox FAIL sox: Sorry, there is no default audio device configured                                                  
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=plughw:CARD=PCH,DEV=0 ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... sox FAIL sox: Sorry, there is no default audio device configured                                                  
error: sox exited with code 1
@user:~/Musik$ AUDIODEV=dsnoop:CARD=PCH,DEV=0 ./Shazam.linux-x64 
SPACE - tag, A - auto, Q - quit
Listening... ALSA lib pcm_dsnoop.c:541:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream                    
sox FAIL sox: Sorry, there is no default audio device configured
error: sox exited with code 1

As you can see, when I use AUDIODEV=default:CARD=PCH, the error is the same as when I don't specify AUDIODEV at all; expected I guess, since "not specified" = "default". The same error with AUDIODEV=sysdefault:CARD=PCH.
Trying some other PCMs, the ALSA-part of the error message disappeared but the sox-part stayed unchanged.
The error message for dsnoop:CARD=PCH,DEV=0 suggests that it is not the right choice, I guess.

I don't really know how to proceed here.

@AlekseyMartynov
Copy link
Owner

As I mentioned in my previous reply, the error originates from the sox utility, not the app code itself.

Please try running the following command in a terminal:

sox -q -d -r 16000 -c 1 -b 16 -e signed-integer test.wav

If this command successfully records a file, the app should work as well.

If you discover that the sox command requires extra parameters to work with your setup, feel free to share. I'll then check how to configure them at the app level.

While I’d love to assist further, I’m not a desktop Linux user. I recommend posting a question on communities like unix.stackexchange.com, sound.stackexchange.com, or other relevant Q&A platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants