def run():
    if len (sys.argv) < 2:
        print ("Usage: %s wavefile" % os.path.basename(sys.argv[0]))
        print ("    Using an example wav file...")
        dirname = os.path.dirname(__file__)
        fname = os.path.join(dirname, "hey.wav")
    else:
        fname = sys.argv[1]


    sink = SoundSink()
    sink.activate()

    source = SoundSource(position=[10, 3, 3])
    source.looping = True

    data = load_wav_file(fname)
    source.queue(data)

    sink.play(source)
    while source.position[0] > -10:
        source.position = [source.position[0] - 1,
                           source.position[1],
                           source.position[2]]
        sink.update()
        print("playing at %r" % source.position)
        time.sleep(1)
    print("done")
예제 #2
0
def mainloop():
    listener = SoundListener()
    listener.orientation = (0, 0, -1, 0, 1, 0)

    sink = SoundSink()
    sink.activate()

    rain = place_sound([0, -7, -1], load_sound("rfrog.wav"), True)
    sink.play(rain)

    birds = place_sound([5, 5, 5], load_sound("chirps1.wav"), True)
    sink.play(birds)

    creek = place_sound([-7, -7, 7], load_sound("creek.wav"), True)
    sink.play(creek)

    while 1 == 1:
        birds.position = move_source_random(birds, -8, 8, 0, 7, -10, 10)
        char = ord(getch.getch())

        if char == 97:
            listener.orientation = orient_listener(listener.orientation, False)

        if char == 100:
            listener.orientation = orient_listener(listener.orientation, True)

        if char == 112:
            break

        sink.update()
import pygame
import random
from openal.audio import SoundSink, SoundSource, SoundListener
from openal.loaders import load_wav_file
from pygame.locals import QUIT, K_LEFT, K_RIGHT, KEYDOWN
import sys

__author__ = 'vamc'

#Initialize OpenAL related components
sound_sink = SoundSink()
sound_source = SoundSource()
listener = SoundListener()
sound_sink.activate()
sound_sink._listener = listener

source_sound_file = "asw.wav"
sound_data = load_wav_file(source_sound_file)
sound_source.queue(sound_data)
sound_source.looping = True

#initialize pygame and screen
pygame.init()
screen_width = 600
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
screen.fill((0, 255, 0))
pygame.display.set_caption('Snake to the sound')

#Create Snake
snake_xpos = [300, 300, 300]