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")
Esempio n. 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")
Esempio n. 3
0
 def __init__(self):
     self.sink = SoundSink()
     self.sink.activate()
     self.listener = SoundListener()
     self.listener.orientation = (0,0,1,0,0,1)
     self.sources = [SoundSource(position = [i, 0, 0], pitch = 1) for i in range(-1, 2, 2)]
     self.intense_sources = [SoundSource(position = [i, 0, 0], pitch = 1) for i in range(-1, 2, 2)]
     #pitch: 5,4,3,2,1
     self.data = load_wav_file("./beep.wav")
     self.intense_data = load_wav_file("./high_beep.wav")
     '''
     for source in self.sources:
         #we want the sources to be looping
         source.looping = True
         source.queue(self.data)
     '''
     for source in self.intense_sources:
         source.looping = True
         source.queue(self.intense_data)
     self.threading_pool = []
     for mild_source in self.sources:
         t = sound_source(self.sink, mild_source)
         self.threading_pool.append(t)
     for intense_source in self.intense_sources:
         t = sound_source(self.sink, intense_source)
         self.threading_pool.append(t)
     #threading pool: mild left; mild right; i left; i right
     #self.sink.play(source1)
     #self.sink.play(source2)
     self.cutoff = [i * (config.MAX_DISTANCE / len(self.sources)) for i in range(len(self.sources))]
Esempio n. 4
0
            def start():
                # Prepare audio feedback
                try:
                    global sink
                    global source
                    global data
                    global ping_delay
                    global ping_pos_x
                    global ping_pos_z
                    global ping_pitch
                    global ping_delay_mult
                    sound_beep = resource_path("beep.wav")
                    ping_delay = 1000
                    ping_pos_x = 0.0
                    ping_pos_z = 0.0
                    ping_pitch = 1.0
                    ping_delay_mult = 2

                    sink = SoundSink()
                    sink.activate()
                    source = SoundSource(position=[ping_pos_x, 0, ping_pos_z])
                    # source.looping = False
                    source.gain = 50.0
                    data = load_wav_file(sound_beep)
                    sink.play(source)
                    print("Audio system started")
                except Exception as e:
                    print("E.Starting Audio: " + str(e))
                    addLogEntry(e)
Esempio n. 5
0
 def __init__(self, parent, wav_file_paths):
     self.parent = parent
     self.wav_file_paths = wav_file_paths
     self.snd_src = None
     self.sink = SoundSink()
     self.sink.activate()
     self.listener = SoundListener()
     self.sink.listener = self.listener
     self.snd_data = []
     for fp in wav_file_paths: self.snd_data.append( load_wav_file(fp) )
     self.wav_file_paths = wav_file_paths
     writeFile(self.parent.log_file_path, '%s, [audioOut], audioOut mod init.\n'%(get_time_stamp()))
Esempio n. 6
0
    def __init__(self):
        pygame.init()
        pygame.font.init()
        pygame.display.set_caption("Surro")
        atexit.register(pygame.quit)

        self.songs = []
        self.sink = SoundSink()
        self.sink.activate()
        self.screen = self.create_screen(640, 480)
        self.clock = pygame.time.Clock()
        self.font = pygame.font.SysFont(self.choose_font(), 70)
        self.has_evil = True
        self.world = None
        self.create_world()
Esempio n. 7
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)
    def __init__(self, conn: DirectConnection):
        self.p = PyAudio()
        atexit.register(self.p.terminate)
        self.stream = None  # type: Stream

        self.sink = SoundSink()
        self.sink.activate()

        self.source = SoundSource()

        def close():
            del self.sink

        atexit.register(close)

        self.source.gain = 1.0
        self.pos = self._pos = (random(), random())
        self.sink.play(self.source)

        self.conn = conn
        self.mic_data = Queue()
        self.speaker_data = Queue()
        self.energy_tracker = EnergyTracker(self.rate)
Esempio n. 10
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
Esempio n. 11
0
from openal.loaders import load_wav_file

sg_input_params = rospy.get_param("/sg/input")
retinal_encoded_image_topic = sg_input_params["retinal_encoded_image"]["topic"]

# Depth camera params
depth_camera_params = rospy.get_param("/depth_camera")
depth_camera_min_depth = depth_camera_params["min_depth"]
depth_camera_max_depth = depth_camera_params["max_depth"]

bridge = CvBridge()

# Audio globals
soundSources = []
soundSourcesSetup = False
soundsink = SoundSink()  # Opening output device

# C-major, the scale of just intonation would be: C=1/1 D=9/8 E=5/4 F= 4/3 G=3/2 A=5/3 B=15/8 C=2/1
C_4 = 264.0
D = 297.0  # C_4 * (9.0/8.0)
E = 330.0  # C_4 * (5.0/4.0)
F = 352.0  # C_4 * (4.0/3.0)
G = 396.0  # C_4 * (3.0/2.0)
A = 440.0  # C_4 * (5.0/3.0)
B = 495.0  # C_4 * (15.0/8.0)
C_5 = 528.0  # C_4 * (2.0/1.0)
min_z = 1000000000
max_z = -1000000000

# TODO: Check if width or height of image chaged, if it did, update it
#       print("reconfigure sound_generator for new depth image")