Beispiel #1
0
 def speak_pygame(self):
     mixer.init()
     mixer.pause()
     mixer.music.load(self.speak_result)
     mixer.music.play()
     self.hibernate()
     mixer.music.stop()
     mixer.unpause()
     mixer.quit()
Beispiel #2
0
 def pauseSound(self):
     global paused
     if(paused == False):
         paused = True
         mixer.pause()
         print("pausing")
     else:
         paused = False
         mixer.unpause()
         print("unpausing")
Beispiel #3
0
    def resume(self):

        """<DOC>
		Resumes playback (if any).

		Example:
		>>> from openexp.sampler import sampler
		>>> src = exp.get_file('my_sound.ogg')
		>>> my_sampler = sampler(exp, src)
		>>> my_sampler.play()
		>>> self.sleep(100)
		>>> my_sampler.pause()
		>>> self.sleep(100)
		>>> my_sampler.resume()
		</DOC>"""

        mixer.unpause()
Beispiel #4
0
    def resume(self):

        mixer.unpause()
Beispiel #5
0
 def _unpause(self):
     pm.unpause()
     self.paused = False
Beispiel #6
0
 def unpause(self):
     mixer.unpause()
Beispiel #7
0
def resume_sound():
    try:
        mixer.unpause()
    except pygame.error:
        pass
Beispiel #8
0
 def set_menu_sound(self, name, val):
     if self.sound and not val:
         mixer.pause()
     elif not self.sound and val:
         mixer.unpause()
     self.sound = val
 def onResume(self):
     mixer.unpause()
    def __init__(self, resolution=(800, 720), fps=60):
        M = 1024  # Slice size

        # Load the song
        songName = "backstage.mp3"

        # Number of FFT bar groups
        self.num_groups = 31

        song = Audio.Audio_fft(songName, M=M, group_num=self.num_groups)

        self.max_amp = song.max_amp
        self.max_amp_raw = song.max_amp_raw

        # Initalise visualiser
        pygame.init()
        # Initialize mixer
        pygame.mixer.quit()
        pygame.mixer.init(frequency=song.rate)
        pygame.mixer.music.load(songName)
        pygame.mixer.music.play(0)

        clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(resolution)

        # Close the program if the user clicks the close button
        done = False
        while not done:
            self.screen.fill(pygame.Color('white'))

            song_time = pygame.mixer.music.get_pos()

            for event in pygame.event.get():
                if (event.type == 2):
                    mixer.pause()
                    time.sleep(2)
                    mixer.unpause()
                if event.type == pygame.QUIT:
                    done = True

            seconds = song_time / 1000

            try:
                scale = int(np.floor(song.rate / M * seconds))
                slice_num = [M * (scale), M * (scale + 1)]

                self.draw_fourier(
                    song.get_fft(slice_num, grouped=True, localAvg=False))
                self.draw_raw(song.get_wave(slice_num))

            except ValueError:
                break

            # Titles on the screen
            FrequencyTitle = pygame.font.Font(None, 30).render(
                "Frequency Spectrum of the Song", True, pygame.Color('black'))
            TimeTitle = pygame.font.Font(None,
                                         30).render("Song Frequency", True,
                                                    pygame.Color('black'))

            self.screen.blit(FrequencyTitle, (260, 320))
            self.screen.blit(TimeTitle, (320, 690))

            # Update the screen
            pygame.display.flip()
            clock.tick(fps)

        pygame.quit()
Beispiel #11
0
    def run(self):

        timer = pygame.time.Clock()
        last_frame_time = 0.0

        for world in self.worlds:

            world.engine = self

            # load the scene of the world before running
            world.start_scene_loading()

            render_system = world.get_system(RenderSystem.tag)

            # failed to obtain the render system
            if render_system is None:
                print("Error. Render system does not exist in the world.")
                return

            # construct the scene order from the initial entities
            render_system.construct_scene(world.entity_manager.entities)

        while True:

            # do not run the game if delta time is too high
            if self.delta_time >= 0.05:
                self.delta_time = 0.0
                continue

            # Get the initial time in milliseconds of the current frame
            frame_start_time = pygame.time.get_ticks()

            if self.print_fps:
                print("FPS: ", timer.get_fps(), "delta time: ",
                      self.delta_time)

            if self.world is None:
                print("Error, the world specified is None.")
                Engine.clean_up()

            # poll input events
            for event in pygame.event.get():
                if event.type == QUIT:
                    Engine.clean_up()

                # key down presses
                elif event.type == pygame.KEYDOWN:

                    # pause the game
                    if event.key == pygame.K_p:
                        self.paused = not self.paused

                        # pause/resume audio
                        if self.paused:
                            mixer.pause()
                            mixer.music.pause()
                        else:
                            mixer.unpause()
                            mixer.music.unpause()

                    # toggle debug mode
                    elif event.key == pygame.K_F12:
                        self.debug = not self.debug

                    elif event.key == pygame.K_F11:
                        self.print_fps = not self.print_fps

                # pass input events to the world
                if not self.paused:
                    self.world._take_input(event)

            # Run the currently set world
            if not self.paused:
                self.world.run()

            # draw gui elements on top of everything
            self.gui.draw_widgets()

            pygame.display.update()

            # The time interval between this frame and the last one.
            # Convert the time from milliseconds to seconds
            self.delta_time = (frame_start_time - last_frame_time) / 1000.0
            last_frame_time = frame_start_time
            timer.tick(self.fps)
Beispiel #12
0
 def play_stream(self,recvdQ, datAvail, shutdown, pause_event, client):
     mixer.init()
     channel = None
     hasLock = False
     end = False
     self.remote_play.set()
     print('playstream active')
     while self.remote_play.is_set() and not shutdown.is_set():#if flag cleared this will hault playback
         #print('playing')
         #print('sample:',data[0:99],len(data))
         if not pause_event.is_set():#stops when user requests pause
             mixer.pause()
             pause_event.wait()
             mixer.unpause()
         if not hasLock:
             #print('wait on datavail')
             hasLock = datAvail.acquire()
             #print('datavail aquired')
         try:
             if recvdQ.full():
                 if channel is None:
                     recvd = recvdQ.get()
                     if len(recvd) > 0:
                         data = recvd.pop(0)
                         recvdQ.put(recvd)
                         if data == 'end' and not channel.get_busy():
                             hasLock = False
                             datAvail.release()
                             break
                         sound = mixer.Sound(buffer = data)
                         #print('first sound buffed')
                         channel = sound.play()
                         channel.pause()
                         hasLock = False
                         datAvail.release()
                     else:
                         #print('wait on data - init')
                         recvdQ.put(recvd)
                         datAvail.wait()
                         #print('init awkoen')
                 else:
                     if not channel.get_queue(): 
                         recvd = recvdQ.get()
                         if len(recvd) > 0 and not end:
                             #print('addnl sound buffed',len(recvd), 'available' )
                             data = recvd.pop(0)
                             recvdQ.put(recvd)
                             #print(data[:2])
                             if data == 'end':
                                 #print('!!!')
                                 end = True
                             if end and not channel.get_busy():
                                 #print('end play')
                                 break
                             channel.queue(mixer.Sound(buffer = data))
                             channel.unpause()
                             hasLock = False
                             datAvail.release()
                         elif end:
                             while True:
                                 #print('addnl sound buffed',len(recvd), 'available' )
                                 data = recvd.pop(0)
                                 channel.queue(mixer.Sound(buffer = data))
                                 channel.unpause()
                                 if not channel.get_busy():
                                    break
                                 recvdQ.put(recvd)
                                 hasLock = False
                                 datAvail.release()
                                 break
                         else:
                             recvdQ.put(recvd)
                             #print('wait on data')
                             datAvail.wait()
                             #print('data awoken')
                     else:
                         #print('wait on queue')
                         hasLock = False
                         datAvail.release()
         except Exception as e: 
             print(e)
             hasLock = False
             datAvail.release()
             pass
     if channel is not None:
         if channel.get_busy():
             channel.stop()
     print('termination our of loop')
     self.remote_play.clear()
     recvd = recvdQ.get()#clear the recieved in case user terminated
     if recvdQ is []:#naturally terminated
         self.func_stream_next() #calls passed function from GUI to play next song
     else:
         print('sending stopper')
         client.sendall(b'S')
         client.close()
     recvdQ.put([])
     recvdQ.put(recvd)
Beispiel #13
0
assignedCards = assignCardsToFolders(audioLibraryPath)

print("start")

mixer.init()
isPaused = False
useRandom = True
while True:
    id, text = cardReader.read()
    if id == PlayPauseCardId:
        if mixer.get_busy():
            if isPaused:
                mixer.pause()
                print("Pause")
            else:
                mixer.unpause()
                print("Unpause")

        else:
            print("Choose and use one of the assigned cards")
    else:
        folder = assignedCards.get(id)
        if folder == None:
            print("Unknown card")
        else:
            playFolder(mixer, folder, useRandom)

# ставим задержку, чтобы одна и та же карта не считывалась несколько раз подряд
sleep(cardReadingDelay)

mixer.quit()
    def main_loop(self):
        # Close the program if the user clicks the close button
        done = False
        frame_count = 0

        prev_seconds = 0
        prev_ccc = np.array([[[0, 0, 0] for j in range(self.jump_fps - 1)]
                             for i in range(1, self.N)])
        shift = 0

        while not done:
            frame_count += 1
            self.screen.fill(pygame.Color('white'))

            song_time = pygame.mixer.music.get_pos()

            for event in pygame.event.get():
                if (event.type == 2):
                    mixer.pause()
                    time.sleep(2)
                    mixer.unpause()
                if event.type == pygame.QUIT:
                    done = True

            seconds = song_time / 1000

            try:
                if frame_count == 1:
                    scale = int(np.floor(self.song.rate / self.M * seconds))
                    #print(prev_seconds,seconds)
                    prev_scale = int(
                        np.floor(self.song.rate / self.M * (prev_seconds)))
                    slice_num = [self.M * (scale), self.M * (scale + 1)]
                    prev_slice = [
                        self.M * (prev_scale), self.M * (prev_scale + 1)
                    ]

                    shift += random.randint(-1, 1)
                    curr_fft = self.song.get_fft(slice_num,
                                                 grouped=True,
                                                 localAvg=False)
                    prev_fft = self.song.get_fft(prev_slice,
                                                 grouped=True,
                                                 localAvg=False)
                    inner_vals = self.interpolate.calc(prev_fft, curr_fft)
                    prev_seconds = seconds
                    ccc = []
                    for i in range(1, self.N):
                        tmp_h_curr = curr_fft[i]
                        if tmp_h_curr > self.width_height[
                                1] - self.left_top[0] // 2:
                            tmp_h_curr = self.width_height[
                                1] - self.left_top[0] // 2

                        # print(tmp_h_curr,tmp_h_prev)
                        if tmp_h_curr > 0:
                            v = (tmp_h_curr / (self.width_height[1] -
                                               self.left_top[0] // 2)) * 15
                        else:
                            v = 0
                        if v > 1:
                            v = 1
                        tmp_rgb = self.hsv_to_rgb(
                            (shift + i) % self.N / (self.N), 0.5, v)
                        tmp_vals = self.interpolate.calc(
                            prev_ccc[i - 1][-1], tmp_rgb)
                        ccc.append(tmp_vals)
                    prev_ccc = ccc
            except ValueError:
                break

            # Set colour for each bar
            for i in range(1, self.N):
                self.bars[i - 1].colour = prev_ccc[i - 1][frame_count - 1]

            self.draw_fourier(inner_vals[frame_count - 1])
            self.draw_raw(self.song.get_wave(slice_num))
            # Titles on the screen
            FrequencyTitle = pygame.font.Font(None, 30).render(
                "Frequency Spectrum of the Song", True, pygame.Color('black'))
            TimeTitle = pygame.font.Font(None,
                                         30).render("Song Frequency", True,
                                                    pygame.Color('black'))

            self.screen.blit(FrequencyTitle, (260, 320))
            self.screen.blit(TimeTitle, (320, 690))

            # Update the screen
            pygame.display.flip()
            self.clock.tick(self.fps)
            if frame_count == self.jump_fps:
                frame_count = 0
        pygame.quit()
 def start(self):
     mixer.unpause()
    def run(self):

        timer = pygame.time.Clock()
        last_frame_time = 0.0

        for world in self.worlds:

            world.engine = self

            # load the scene of the world before running
            world.start_scene_loading()

            render_system = world.get_system(RenderSystem.tag)

            # failed to obtain the render system
            if render_system is None:
                print("Error. Render system does not exist in the world.")
                return

            # construct the scene order from the initial entities
            render_system.construct_scene(world.entity_manager.entities)

        while True:

            # do not run the game if delta time is too high
            if self.delta_time >= 0.05:
                self.delta_time = 0.0
                continue

            # Get the initial time in milliseconds of the current frame
            frame_start_time = pygame.time.get_ticks()

            if self.print_fps:
                print("FPS: ", timer.get_fps(), "delta time: ", self.delta_time)

            if self.world is None:
                print("Error, the world specified is None.")
                Engine.clean_up()

            # poll input events
            for event in pygame.event.get():
                if event.type == QUIT:
                    Engine.clean_up()

                # key down presses
                elif event.type == pygame.KEYDOWN:

                    # pause the game
                    if event.key == pygame.K_p:
                        self.paused = not self.paused

                        # pause/resume audio
                        if self.paused:
                            mixer.pause()
                            mixer.music.pause()
                        else:
                            mixer.unpause()
                            mixer.music.unpause()

                    # toggle debug mode
                    elif event.key == pygame.K_F12:
                        self.debug = not self.debug

                    elif event.key == pygame.K_F11:
                        self.print_fps = not self.print_fps

                # pass input events to the world
                if not self.paused:
                    self.world._take_input(event)

            # Run the currently set world
            if not self.paused:
                self.world.run()

            # draw gui elements on top of everything
            self.gui.draw_widgets()

            pygame.display.update()

            # The time interval between this frame and the last one.
            # Convert the time from milliseconds to seconds
            self.delta_time = (frame_start_time - last_frame_time)/1000.0
            last_frame_time = frame_start_time
            timer.tick(self.fps)
Beispiel #17
0
def resume_sound():
    try:
        mixer.unpause()
    except pygame.error:
        pass
Beispiel #18
0
	def resume(self):

		mixer.unpause()