4

If I start my python program as root (I have to start it as root cause the keyboard-module) this problem accrued:

ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
Stopping program
Stopping program
Traceback (most recent call last):
  File "[...]/run.py", line 26, in <module>
    main()
  File "[...]/run.py", line 11, in main
    GameStateManager.change_gamestate(SetupState())
  File "[...]/src/game_state.py", line 103, in __init__
    self.setup_sound_manager()
  File "[...]/src/game_state.py", line 110, in setup_sound_manager
    GameState.sound_manager = SoundManager()
  File "[...]/src/utils.py", line 253, in __init__
    mixer.init()
pygame.error: ALSA: Couldn't open audio device: No such file or directory

If I run a a sound manually with sudo aplay test.wav than this error comes up:

ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave

System

                    /-                      
                   ooo:                     ----------------------------
                  yoooo/                    OS: ArcoLinux
                 yooooooo                   Kernel: 5.17.4-arch1-1
                yooooooooo                  Uptime: 3 days, 23 hours, 2 mins
               yooooooooooo                 Packages: 1373 (pacman)
             .yooooooooooooo                Shell: zsh 5.8.1
            .oooooooooooooooo               Resolution: 1920x1080
           .oooooooarcoooooooo              WM: i3
          .ooooooooo-oooooooooo             Theme: Arc-Dark [GTK2/3]
         .ooooooooo-  oooooooooo            Icons: Sardi-Arc [GTK2/3]
        :ooooooooo.    :ooooooooo           Terminal: alacritty
       :ooooooooo.      :ooooooooo          CPU: AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx (8) @ 2.000GHz
      :oooarcooo         .oooarcooo         GPU: AMD ATI Radeon Vega Series / Radeon Vega Mobile Series
     :ooooooooy           .ooooooooo        Memory: 2015MiB / 6904MiB (29%)
    :ooooooooo   /ooooooooooooooooooo
   :ooooooooo      .-ooooooooooooooooo.
  ooooooooo-             -ooooooooooooo.
 ooooooooo-                 .-oooooooooo.
ooooooooo.                     -ooooooooo
N1CK145
  • 59
  • 1
  • 11

2 Answers2

0

Try to give full path of your sound file. Such as:

your/full/path/to/file/test.wav

If this didn't work, Your SDL default sound driver is alsa. You can change your sound driver using this command:

import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'
# Your code

Put these two lines very top of your code.

0

You MUST initialize pygame using pygame.init() to use the mixer.

M--
  • 25,431
  • 8
  • 61
  • 93
  • Sorry for my late response. I did initialize the mixer. It semes like the problem is on the OS site. I did changed from ArcoLinux to Manjaro. Here i didn't had a problem like this. – N1CK145 Jul 02 '23 at 22:12