[Python] pygame.error: ALSA: Couldn't open audio device: Unknown error 524, What is going on?

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a function that takes text and turns it into a .wav file using pyttsx3 on an RPi4B, then using pygame it plays the .wav file (I know pyttsx3 has a built in function for this but we got different and harder to diagnose errors from it), but it seems to be conflicting with ALSA, it works on windows just fine but on the RPi it breaks

    this is the code here (For inputOutput):

    '''File to utilise the speaker system'''
    import pyttsx3
    import pygame
    import os

    pygame.init()
    mix = pygame.mixer
    mix.init()
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    engine.setProperty('voice', voices[12].id)
    engine.setProperty('rate', 155)


    # Function to convert text to
    # speech
    def SpeakText(command):
    # Initialize the engine
    engine.save_to_file(command, "Words.wav")
    engine.runAndWait()
    mix.music.load("Words.wav")
    mix.music.play()
    while pygame.mixer.music.get_busy() == True:
    continue
    mix.music.unload()
    if os.path.exists("Words.wav"):
    os.remove("Words.wav")
    else:
    print("The file does not exist")



    the full error that is being raised is:

    pygame 2.1.2 (SDL 2.26.5, Python 3.11.2)
    Hello from the pygame community. https://ww.pygame.org/contribute.html
    Traceback (most recent call last):
    File "/home/user/Project-Sigmund/main.py", line 4, in <module>
    import inputOutput #name of file
    File "/home/user/Project-Sigmund/inputOutput.py", line 7, in <module>
    mix.init()
    pygame.error: ALSA: Couldn't open audio device: Unknown error 524


    I've tried various different threads but nothing is working

    This program does work on windows and generates the expected result, just not on RPi

    Continue reading...

Compartilhe esta Página