2019-03-30 05:37:05

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

2019-03-30 05:49:58

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()
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-03-30 08:13:50

thankyou very much poast 2.