pygame.error: WASAPI can’t initialize audio client:

  audio, pygame, python

pygame can’t play audio, but when I have my bluetooth speakers connected there is no error. When I disconnect my bluetooth speakers this error happens. Also I’m on a laptop, so I’m trying play the audio using the built-in speakers. Other apps can play audio just fine. And I’m running this inside a virtualenv. but I’ve only installed pygame in this virtualenv. Here’s the code in my game that deals with the audio:

import pygame
import os
from fractions import Fraction
from random import randint
pygame.init()
pygame.mixer.init()

snake_eat_sound = pygame.mixer.Sound(os.path.join('Assets', 'Biting Apple-SoundBible.mp3'))
snake_hit_sound = pygame.mixer.Sound(os.path.join('Assets', 'mixkit-arcade-mechanical-bling.mp3'))

snake_eat_sound.play()
snake_hit_sound.play()

And here is the error it produces:

Traceback (most recent call last):
  File "d:Programmingprojectspythonpygame_snake_exercisemain.py", line 6, in <module>
    pygame.mixer.init()
pygame.error: WASAPI can't initialize audio client: 
(pygame_env) PS D:Programmingprojectspythonpygame_snake_exercise> 

Source: Python Questions

LEAVE A COMMENT