Jump to content

Playing sound

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
mevets

mevets

    Newbie

  • Members
  • PipPip
  • 11 posts
[SOLVED] - I am making an alarm clock in python. This requires me to play a sound file just once. What is the easiest method to play a wav or ogg? I looked into the solutions and I saw people recommend pyMedia and ossaudiodev. Is pyGame a good idea?

Also, how would I even start to import something like pyGame? I know to add import pygame, but I do not know where I should put all the pygame code.
Steve M.

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Which platform are you using?
I only know one way, if you are going to use the standard libraries, but it's only compatible with Windows.
import winsound
winsound.PlaySound("sound.wav", winsound.SND_FILENAME)
So if you're aiming for making your script cross-platform, or if you're on another platform, you probably need to use some third-party library, but I can't say which one is good for your purpose.

It's pretty easy to install new libraries. In your Python-directory, you've a file called "Lib," you just need to place the files in there. The library will probably have a README og INSTALL file, which would help you, if it need configuration, or something else first.

#3
mevets

mevets

    Newbie

  • Members
  • PipPip
  • 11 posts
I am using linux. Someone said pyGame would be easiest. Does anyone know where pythons lib folder is located under linux? I saw /var/lib/python2.5. Is that it?
Steve M.

#4
mevets

mevets

    Newbie

  • Members
  • PipPip
  • 11 posts
import pygame works but I had to first

sudo apt-get install python-pygame


Steve M.