Hi there, i was wandering about how to inplumant a music track into my script or even a sound? should i use the pigame librarry to do that? any help would be apreciated
Pages 1
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → adding sounds to a python script.
Hi there, i was wandering about how to inplumant a music track into my script or even a sound? should i use the pigame librarry to do that? any help would be apreciated
Yes, you can use pygame, although it only has basic audio capabilities, no 3D positional audio or reverb effects. Alternatively you can also use my OpenAL Examples which you can find [here] which come with a few examples on more advanced audio. To help get you started, here's a few pygame examples using both pygames built in audio, and the OpenAL script:
import pygame
from pygame import mixer
import sys
def Example():
#initialize pygame
pygame.init()
#initialize sound mixer
mixer.init()
#create display
window = pygame.display.set_mode([640,480])
#load sound
sound = mixer.Sound('tone5.wav')
#main update loop
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
#if space is pressed, play sound
if event.key == pygame.K_SPACE:
sound.play()
#if escape is pressed, quit
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit(0)
#update window
pygame.display.update()
Example()
And with OpenAL:
import pygame
from openal import *
import sys
def Example():
#initialize pygame
pygame.init()
#load listener for hearing sound
listener = Listener()
#load sound object
sound = LoadSound('tone5.wav')
#load player for playing sound
player = Player()
#load sound object into player
player.add(sound)
#create display
window = pygame.display.set_mode([640,480])
#main update loop
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
#if space is pressed, play sound
if event.key == pygame.K_SPACE:
player.play()
#if escape is pressed, clean up and quit
if event.key == pygame.K_ESCAPE:
player.delete()
sound.delete()
listener.delete()
pygame.quit()
sys.exit(0)
#update window
pygame.display.update()
Example()
AudioGames.net Forum → Developers room → adding sounds to a python script.
Generated in 0.015 seconds (49% PHP - 51% DB) with 11 queries