0

I just got my RPi and it used to be able to play tones with winsound. Now, I get an error when I try to import it. Do I have to reimage?

File "/home/pi/Py_Progs/tones1.py", line 1, in import winsound ImportError: No module named 'winsound'

2

From https://docs.python.org/2/library/winsound.html :

35.4. winsound — Sound-playing interface for Windows

The Raspberry Pi is not a Windows computer, it is a Linux computer. You will need to use a different sound library to be able to play sounds from Python on the RPi.

These questions over on our sister site StackOverflow give some options:

https://stackoverflow.com/questions/12354586/python-what-are-the-nearest-linux-and-osx-equivalents-of-winsound-beep

https://stackoverflow.com/questions/13150267/convert-winsound-to-a-linux-platform

The best recommendation I have been able to get from a quick search is to utilize the pygame module instead of winsound, like so (courtesy of the accepted answer in the second StackOverflow link above):

import pygame

pygame.init()

pygame.mixer.music.load("ding.wav")

pygame.mixer.music.play()
| improve this answer | |
  • When I first got the RPi it would play sounds with winsound. Now I get an error importing it. I can't get sounds from anywhere now. Even SonicPi doesn't work. I can import pygame but no noise when I run the script you provided. Must be something else like maybe even hardware. I'll keep fooling around. How much can I mess it up anyway? Thanks for answering. – hcappy Jan 6 '17 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.