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 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()

    xint = int(x.get())
    yint = int(y.get())
    zint = int(z.get())
    source = SoundSource(position=[xint, yint, zint])
    source.looping = False

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

    sink.play(source)

    sink.update()
    time.sleep(2)
    print("done")
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")
Пример #4
0
def make_sounds(items):

    sink = SoundSink()
    sink.activate()

    print("Frame with these items: " + str([item.label for item in items]))

    for item in items:
        label = item.label.strip()
        position = item.box.center
        area = item.box.area

        source_x = (position[0] - frame_width / 2) / (frame_width / 2) * 5
        source_z = -1 / math.sqrt(area / frame_area)

        print("{label} @ ({x:2f}, {z:2f})".format(label=label,
                                                  x=source_x,
                                                  z=source_z))

        base_name = os.path.join(temp_path, label)
        wav_file = base_name + ".wav"

        if (not os.path.exists(wav_file)):

            tts = gTTS(label)
            tts.save(base_name + '.mp3')

            sound = AudioSegment.from_mp3(base_name + '.mp3')
            sound.export(wav_file, format="wav")

        data = load_wav_file(wav_file)

        duration = 0.0

        with contextlib.closing(wave.open(wav_file, 'r')) as f:
            frames = f.getnframes()
            rate = f.getframerate()
            duration = frames / float(rate)

        source = SoundSource(position=[0, 0, 0])
        source.looping = False
        source.queue(data)

        sink.play(source)
        source.position = [source_x, 0, source_z]
        sink.update()
        time.sleep(duration + 0.1)
    def Start():
        #Prepare audio feedback
        try:
            global sink
            global source
            global data

            sink = SoundSink()
            sink.activate()
            source = SoundSource(position=[0, 0, 50])
            source.looping = False
            source.gain = 50.0
            data = load_wav_file(sound_beep)
            #source.queue(data)
            sink.play(source)
            print("Audio system started")
        except Exception as e:
            print("E.Starting Audio:" + str(e))
            AddLogEntry(e)
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]
snake_ypos = [300, 290, 280]
snake_cell_size = 20
snake_image = pygame.Surface((snake_cell_size, snake_cell_size))
snake_image.fill((64, 0, 0))
Пример #7
0
import time
import math
from openal.audio import SoundSink, SoundSource
from openal.loaders import load_wav_file

if __name__ == "__main__":
    sink = SoundSink()
    sink.activate()
    source = SoundSource(position=[0, 0, 0])
    source.looping = True
    data = load_wav_file("./sounds/Blip_Select.wav")
    source.queue(data)
    sink.play(source)
    t = 0
    while True:
        x_pos = 5 * math.sin(math.radians(t))
        source.position = [x_pos, source.position[1], source.position[2]]
        sink.update()
        print("playing at %r" % source.position)
        time.sleep(0.1)
        t += 5
Пример #8
0
def place_sound(pos, wav, loop_bool):
    source = SoundSource(position=pos)
    source.queue(wav)
    source.looping = loop_bool
    return source
Пример #9
0
import os
import sys
import wave
from openal.audio import SoundData
from openal.loaders import load_wav_file
from openal.audio import SoundSink, SoundSource, SoundListener
import time
import math

if __name__ == "__main__":
    sink = SoundSink()
    sink.activate()
    listener = SoundListener()
    listener.orientation = (0,0,1,0,0,1)
    source1 = SoundSource(position=[0, 0, 3])
    source1.looping = True
    source2 = SoundSource(position=[0, 0, 3],pitch=2.0)
    source2.looping = True
    data2 = load_wav_file("./hey.wav")
    source1.queue(data2)
    source2.queue(data2)
    sink.play(source1)
    sink.play(source2)
    t = 0
    while True:
        x_pos = 5*math.sin(math.radians(t))
        source1.position = [x_pos, source1.position[1], source1.position[2]]
        source2.position = [0, source2.position[1], source2.position[2]]
        sink.update()
        print("playing source 1 at %r" % source1.position)
        print("playing source 2 at %r" % source2.position)