Python Audio Files Output

How do I play an audio file in python? I’ve tried using pygame and playsound both of those return an error message in which it basically says there is no audio output connected or something.

My code currently
Repl link:

###############################################
cpu = ("""█████████████
█╔═════════╗█
█║{screens}║█
█╚════╦════╝█
█  ▒ ═╩═ ▒  █
█╒═════════╕█
█│qwertyu↕=│█
█│◘⌂^@⌐¬◘↔▲│█
█╘═════════╛█
█████████████""")
act = ""  #place holder, will be edited by user
goal = "WIN"  #place holder, will be edited by PROGRAMMER for proper answer
variables.character_count = 9  #"freespace" of ui and limiter
print(variables.lspace)
print(cpu.format(screens=variables.space *
                 (variables.character_count)))  # ui shown


def CpuGame():
  global character_count, act, reset, set, space
  variables.character_count = variables.reset
  act = input("Action?\n")
  act = act.upper()

  for _x in act:
    variables.character_count += 1
    #character variables.counter to find out how many freespaces required

  if variables.character_count <= 9:  #character limit
    print(
        cpu.format(screens=act + variables.space *
                   (9 - variables.character_count)))

  elif (variables.character_count == 0 or variables.character_count > 9
        or act == "error" or act == ""):
    print(cpu.format(screens="error" + variables.space * (4)))
    print("retry")
    CpuGame()

  else:
    pass


while act != goal:
  if variables.counter == 0:
    print("Asked", variables.counter, "many times now\n")
  else:
    print("\n\nAsked", variables.counter, "many times now\n")
  CpuGame()
  variables.counter += 1
else:
  print("You Win!")
  print(mixer.get_init())
  mixer.music.load('cartoon_success_fanfair.mp3')
  mixer.music.set_volume(0.9)
  mixer.music.play(3)

the last else is where i get the issue

Pygame audio does not seem to be working. (Maybe replit audio works but I haven’t tested it.) It used to work in the past.
Older repls still have working audio, repls with prybar and venv.

Audio on replit has always been unreliable though.

damn it. so there is no hope to using audio in my repl?

I would never rely on replit for having audio (it might not work on some browsers).

However, the replit package’s audio has not been tested, you could look into that.
If that doesn’t work and you really need audio, you can find a pygame repl that has older configuration, fork it, and use that instead. (Obviously, using old templates is a bit bad). You could also create a bug report but it would probably take a long time for it to be looked at (if at all).

2 Likes

thanks for that, but that really is disheartening isn’t it?

1 Like

Yes.
Replit’s audio has always been quite bad for everything except music, there is usually some latency, etc.
https://docs.replit.com/tutorials/replit/playing-audio-replit#known-limitations
(if this topic is done, mark a post as solution)

Glad someone asked this. I have been going nuts trying to get audio play. I knew I had previously in Replit but I haven’t been able to get it working this week. Sounds like I may not be the problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.