How do i play sound in python?

This is the place for queries that don't fit in any of the other categories.

How do i play sound in python?

Postby dannyxy » Sat May 11, 2013 2:01 pm

.mp3 .wav .amr and others
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: How do i play sound in python?

Postby Mekire » Sat May 11, 2013 2:08 pm

Your question seems a tad too general. I would use pygame personally. What are you trying to do exactly?

-Mek
User avatar
Mekire
 
Posts: 977
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: How do i play sound in python?

Postby dannyxy » Sat May 11, 2013 2:18 pm

A very simple music player
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: How do i play sound in python?

Postby Mekire » Sat May 11, 2013 2:28 pm

This gets a song playing on repeat:
Code: Select all
import pygame as pg
import sys,random

pg.init()
screen = pg.display.set_mode((500,500))
clock = pg.time.Clock()

pg.mixer.music.load("YOUR FILE NAME GOES HERE")
pg.mixer.music.play(-1)

while 1:
    keys = pg.key.get_pressed()
    for event in pg.event.get():
        if event.type == pg.QUIT or keys[pg.K_ESCAPE]:
            pg.quit();sys.exit()
    clock.tick(60)

-Mek
User avatar
Mekire
 
Posts: 977
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: How do i play sound in python?

Postby hansn » Sat May 11, 2013 2:31 pm

Here is some information on python audio. http://wiki.python.org/moin/Audio/
hansn
 
Posts: 87
Joined: Thu Feb 21, 2013 8:46 pm

Re: How do i play sound in python?

Postby Guitarman2010 » Wed May 15, 2013 7:01 pm

Using Python on the Android platform simplifies audio playing.

Code: Select all
#Example of playing an .mp3 file with Python4Android

import android
droid = android.Android() #initiates module

droid.mediaPlay('/sdcard/test.mp3')
Guitarman2010
 
Posts: 11
Joined: Thu Mar 07, 2013 4:39 pm

Re: How do i play sound in python?

Postby dannyxy » Fri May 24, 2013 1:46 am

I tried pygame and it worked but if i try to change the current song thet is playing by stoping the current song, loading a new one and playing it, it won't play unless i call the pygame.mixer.music.play() function like 3 times before it plays, is there a way to change the song without have having to call the play() function 3 times. Thanks
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: How do i play sound in python?

Postby Mekire » Fri May 24, 2013 3:44 am

dannyxy wrote:I tried pygame and it worked but if i try to change the current song thet is playing by stoping the current song, loading a new one and playing it, it won't play unless i call the pygame.mixer.music.play() function like 3 times before it plays, is there a way to change the song without have having to call the play() function 3 times. Thanks
This is almost definitely an issue with your code and not with pygame. I would have to see some more details to diagnose.

-Mek
User avatar
Mekire
 
Posts: 977
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests