OS X: How to play .wav file w/Python?

K

kj

Hi. I'm trying to learn how to play a .wav file in OS X with Python.
I tried the following, which ran without errors, but produced
nothing audible (even though the file bell.wav plays perfectly well
otherwise, e.g. view the Finder's Preview):

import pygame.mixer

pygame.mixer.init()
pygame.mixer.Sound("bell.wav").play
print "done"


What am I doing wrong?

TIA!

kynn
 
A

alex23

import pygame.mixer

pygame.mixer.init()
pygame.mixer.Sound("bell.wav").play
print "done"

What am I doing wrong?

Your first mistake is not pasting here the traceback you received.
That always makes it easier to assist with problems like this.

However, my guess is it's this line:
pygame.mixer.Sound("bell.wav").play

'play' is a method, which means you need to call it. Try the following
instead:
pygame.mixer.Sound("bell.wav").play()

And let us know how that goes :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top