def music_player(): #function defination mi.init() mu.set_volume(0.7) mu.load(random.choice(songs)) print( "*******************************************************************") print("\t\tWELCOME TO MY MUSIC_PLAYER") print( "*******************************************************************") print("press 'a' to PLAY | press 'r' to RESUME | press 'n' for next song") print("press 's' to STOP | press 'p' to PAUSE") print( "--------------------------------------------------------------------\n" ) while True: query = input("") if query == 'a': mu.play() print("Player Start!") elif query == 'r': mu.unpause() print("Song resume") elif query == 'p': print("song pause!") mu.pause() elif query == 'n': print("Listen next song!") mu.stop() time.sleep(1) mu.load(random.choice(songs)) mu.play() elif query == 's': mu.stop() break print("Player get quit !")
def play(self, music): if not music: return if self.now_playing != music: music_player.load(music) music_player.play(-1) # music_player.set_volume(0.5) self.now_playing = music
def prep_square(last_square): World.current_Square.tier = Player.level // 5 + 1 rng = randint(0, 9) if World.current_Square.type is None: if rng > 1 and last_square.type != "start": World.current_Square.type = last_square.type World.current_Square.music = last_square.music else: World.current_Square.type = World.current_Square.rand_type() World.current_Square.description = World.current_Square.get_description() Screen.delete("0.1", END) Screen.insert(INSERT, f"{World.current_Square.description}") if World.current_Square.Floor is not None: Screen.insert(INSERT, f"\n{World.current_Square.Floor.Name} is sitting on the floor...\n") if World.current_Square.NPCs is None and World.current_Square.state != "clear": World.current_Square.NPCs = Enemy(World.current_Square.tier - 1) if World.current_Square.NPCs.name in Enemies[World.current_Square.tier - 1]: Screen.insert(INSERT, appear(World.current_Square.NPCs.name)) Player.combat = True if Everything.doneCombat is False: intro_combat() Everything.doneCombat = True elif World.current_Square.NPCs.name in NPC: World.current_Square.state = "clear" if World.current_Square.NPCs.name is None: pass else: if appear_npc(World.current_Square.NPCs.name) not in ["gamble", "trade"]: Screen.insert(INSERT, appear_npc(World.current_Square.NPCs.name)) elif appear_npc(World.current_Square.NPCs.name) == "gamble": gamble() elif appear_npc(World.current_Square.NPCs.name) == "trade": x = trade() Everything.Trade = x else: World.current_Square.state = "clear" elif World.current_Square.NPCs is not None and World.current_Square.state != "clear": Screen.insert(INSERT, appear(World.current_Square.NPCs.name)) Player.combat = True elif World.current_Square.NPCs is not None and World.current_Square.state == "clear": if World.current_Square.NPCs.name is None: pass else: if appear_npc(World.current_Square.NPCs.name) not in ["gamble", "trade"]: Screen.insert(INSERT, appear_npc(World.current_Square.NPCs.name)) elif appear_npc(World.current_Square.NPCs.name) == "gamble": Screen.insert(INSERT, "You see a gambler but he seems busy...\n") elif appear_npc(World.current_Square.NPCs.name) == "trade": Screen.insert(INSERT, "You see a trader but he seems busy...\n") if last_square.music != World.current_Square.music: mixer_music.fadeout(500) mixer_music.load(f"Music/{World.current_Square.music}.mp3") mixer_music.play(-1) Everything.map_uptodate = False save()
def playTheSong(self, *args): self.musicCtrl.playBtn.setVisible(False) self.musicCtrl.playBtn.setEnabled(False) self.pauseBtn.setVisible(True) self.pauseBtn.setEnabled(True) self.playSong = SongThread(self.progressBar.roundProgress.value(), self.playBackSong) self.playSong.start() self.playSong.dePauseTimeline() self.playSong.runTime.connect(self.updateTimeline) print "Entered play" _mixer.play()
def next_song(self): if self.is_file_get: self.song_ptr += 1 if self.song_ptr == len(self.listfile) - 1: showinfo(title='Info', message='End of list') self.song_ptr = 0 try: mx.stop() except Exception as e: pass data = mx.load(self.listfile[self.song_ptr]) mx.play() self.playing = True else: showinfo(title="Directory not found", message='Directory is not set')
def prev_song(self): if self.is_file_get: self.song_ptr -= 1 if self.song_ptr < 0: showinfo(title='Info', message='First music of list') self.song_ptr = 0 try: mx.stop() except Exception as e: pass data = mx.load(self.listfile[self.song_ptr]) mx.play() self.playing = True else: showinfo(title="Directory not found", message='Directory is not set')
def nextSong(): global playtime, auxSlide, currentSong, progressBar, currentSongNameLabel, pathToFile music.stop() playtime = 0 progressBar.set(0) if currentSong == len(playlist) - 1: music.load(playlist[0]) music.play(0, 0) currentSong = 0 else: music.load(playlist[currentSong + 1]) music.play(0, 0) currentSong = currentSong + 1 changeName(currentSongNameLabel) audio = MP3(playlist[currentSong]) auxSlide = audio.info.length progressBar.configure(to=auxSlide)
def adaptMusic(self, emotion): if emotion in {'happy', 'neutral', 'angry'}: if self.emotion != emotion: self.emotion = emotion if mixer_music.get_busy(): mixer_music.fadeout(500) else: if mixer_music.get_volume() <= .95: mixer_music.set_volume(mixer_music.get_volume() + 0.010) if not mixer_music.get_busy(): mixer_music.set_volume(0) if emotion == 'happy': mixer_music.load("lib/happy.mp3") elif emotion == 'angry': mixer_music.load("lib/angry.mp3") else: mixer_music.load("lib/neutral.mp3") mixer_music.play()
def playSong(): global playtime global firstClick global pausePlayClock if firstClick == 1: music.play(0) playButton['text'] = 'Pause' firstClick = 0 else: if (pausePlayClock == 1): music.play(0, playtime) playButton['text'] = 'Pause' pausePlayClock = 0 else: music.stop() playButton['text'] = 'Play!' pausePlayClock = 1 window.after(1000, loopScale)
def start(): if DB_player is None: mixer_music.load("Music/start.mp3") mixer_music.play(-1) mixer.music.set_volume(0.4) Screen.insert(INSERT, "You wake up in a forest glade,\nthe morning sun blinding you,\n" "the sounds of birds and critters around you.\n" "They are so loud your head hurts\n\"Am I hungover?\", you think..." "\n\nSome water would do wonders.\n" "You look around and spot a pond at the edge\nof the glade...\n") Log.insert(INSERT, "Log:\n" "You woke up\n") logs_.append("Log:\nYou woke up\n") else: mixer_music.load(f"Music/{World.current_Square.music}.mp3") mixer_music.play(-1) mixer.music.set_volume(0.4) Screen.insert(INSERT, World.current_Square.description) for element in logs_: Log.insert(INSERT, element) Screen.config(state=NORMAL) Screen.insert(INSERT, "You wake up from your nap...\n\n") Screen.insert(INSERT, World.current_Square.description) if World.current_Square.Floor is not None: Screen.insert(INSERT, f"\n{World.current_Square.Floor.Name} is sitting on the floor...\n") if World.current_Square.state != "clear": Screen.insert(INSERT, "\nThe enemy got bored of waiting and went away...\n") Player.combat = False Player.busy = False World.current_Square.NPCs = None World.current_Square.Floor = None elif Everything.trading is True or Everything.gambling is True: Screen.insert(INSERT, "\n The figure is gone...\nI guess they had better things to do than wait...\n") Everything.trading = False Everything.gambling = False Screen.config(state=DISABLED) Log.see("end")
def run(self): mixer.init(44100, -16, 2, 2048) rand = random.choice(self.path_and_file) map_title = str(rand[0]).split("\\")[-1] mixer_music.load(f"{rand[0]}\{rand[1]}") mixer_music.play() mixer_music.set_endevent(self.NEXT) mixer_music.set_volume(self.volume) self.signals.signal_str.emit(map_title) running = True while running: for event in pygame.event.get(): if event.type == self.NEXT: rand = random.choice(self.path_and_file) map_title = str(rand[0]).split("\\")[-1] self.signals.signal_str.emit(map_title) mixer_music.load(f"{rand[0]}\{rand[1]}") mixer_music.play()
def sideController(event): global auxSlide, playtime, progressBar if music.get_busy(): music.play(0, (event.x / 450) * auxSlide) music.stop() playtime = (event.x / 450) * auxSlide progressBar.set(playtime) music.load(playlist[currentSong]) music.play(0, (event.x / 450) * auxSlide) else: music.play(0, (event.x / 450) * auxSlide) music.stop() playtime = (event.x / 450) * auxSlide progressBar.set(playtime) music.load(playlist[currentSong])
def playMusic(): """ A function that plays music. It loads the song from the playlist and plays it. """ player.load(MyPlaylist.filename) player.play()
def run(): app = ArtStudioApp() canvasPage = app.frames[CanvasPage] screen_width = int(app.winfo_screenwidth()*.75) screen_height = int(app.winfo_screenheight()*.75) #Setup Speech Multithreading speech_callback_queue = queue.Queue() def speech_callback(recognizer, audio): ''' Callback function for when audio is heard on separate thread. Uses Google Speech recognition to translate audio to text and the text is then parsed for keywords. ''' print("Audio received") try: spoken = recognizer.recognize_google(audio).lower() text = "You said: " + spoken print(text) speech_callback_queue.put(lambda: canvasPage.speech.set(text)) words = spoken.split() if "red" in words: func = lambda: canvasPage.change_fg(RED) speech_callback_queue.put(func) elif "blue" in words: func = lambda: canvasPage.change_fg(BLUE) speech_callback_queue.put(func) elif "orange" in words: func = lambda: canvasPage.change_fg(ORANGE) speech_callback_queue.put(func) elif "green" in words: func = lambda: canvasPage.change_fg(GREEN) speech_callback_queue.put(func) elif "yellow" in words: func = lambda: canvasPage.change_fg(YELLOW) speech_callback_queue.put(func) elif "purple" in words: func = lambda: canvasPage.change_fg(PURPLE) speech_callback_queue.put(func) elif "black" in words: func = lambda: canvasPage.change_fg('black') speech_callback_queue.put(func) elif "eraser" in words: func = lambda: canvasPage.change_fg(eraser=True) speech_callback_queue.put(func) elif all(item in ['what', 'should', 'i', 'draw'] for item in words) or \ all(item in ['new', 'suggestion'] for item in words): func = lambda: canvasPage.generate_suggestion() speech_callback_queue.put(func) elif "brush" in words and "size" in words: prior = words.index("size") try: size = words[prior+1] func = lambda: canvasPage.change_penwidth(size=size) speech_callback_queue.put(func) except IndexError: pass elif "change" in words and "custom" in words and "color" in words: func = lambda: canvasPage.change_fg() speech_callback_queue.put(func) elif "custom" in words: func = lambda: canvasPage.change_fg(canvasPage.color_custom) speech_callback_queue.put(func) elif "clear" in words: func = lambda: canvasPage.clear() speech_callback_queue.put(func) elif "undo" in words: speech_callback_queue.put(canvasPage.undo) elif "save" in words: speech_callback_queue.put(canvasPage.save) elif "quit" in words or "exit" in words or "close" in words: speech_callback_queue.put(canvasPage.master.destroy) elif "home" in words: speech_callback_queue.put(lambda: app.show_frame(MainPage)) elif "help" in words: speech_callback_queue.put(lambda: app.show_frame(HelpPage, state="HELP")) except sr.UnknownValueError: speech_callback_queue.put(lambda: canvasPage.speech.set("You said: ... ")) print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) #Setup Speech Recognition r = sr.Recognizer() r.energy_threshold = 12000 m = sr.Microphone() with m as source: r.adjust_for_ambient_noise(source) stop_listening = r.listen_in_background(m, speech_callback, phrase_time_limit=3) #Setup Emotion Recogntion faceCascade = app.face_cascade video_capture = app.vs emotionStore = {} emotionCount = 0 #Setup Gesture Smoothing store = [] recent = None #Setup Audio pygame.init() mixer_music.load("lib/neutral.mp3") mixer_music.play() #Main loop while True: try: # Capture frame-by-frame ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) # Draw a rectangle around the faces for (x, y, w, h) in faces: #Crop, Resize, Gray, & Reshape Image cropped_img = frame[y:y+h, x:x+w].copy() resized_img = cv2.resize(src=cropped_img, dsize=(48, 48), interpolation=cv2.INTER_AREA) grayed_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2GRAY) reshaped_img = grayed_img.reshape((48, 48, 1)) label = label_image(app.model, reshaped_img) emotionStore[label] = emotionStore.get(label, 0) + 1 emotionCount += 1 if emotionCount >= 100: print(emotionStore) if emotionStore.get("angry", 0) >= 40 and emotionStore.get("angry", 0) > emotionStore.get("happy", 0): prevalent = "angry" elif emotionStore.get("happy", 0) >= 40 and emotionStore.get("happy", 0) > emotionStore.get("angry", 0): prevalent = "happy" else: prevalent = "neutral" canvasPage.adaptRGB(prevalent) canvasPage.adaptMusic(prevalent) emotionStore = {} emotionCount = 0 else: canvasPage.adaptRGB(canvasPage.emotion) canvasPage.adaptMusic(canvasPage.emotion) #Get Gesture Data each frame hand = getLeapFrame().hands[0] pointer_position_mm = list(hand.palm_pos) if pointer_position_mm != [0, 0, 0] and is_in_bounds(pointer_position_mm): x, y, z = mm_to_px(screen_width,screen_height,pointer_position_mm) store.append((x,y,z)) if len(store) >= 1: avg_x = sum([a[0] for a in store])/len(store) avg_y = sum([a[1] for a in store])/len(store) avg_z = sum([a[2] for a in store])/len(store) canvasPage.move_cursor_to(avg_x, avg_y) if avg_z <= -20: canvasPage.gesture_paint(avg_x, avg_y) canvasPage.fill_cursor() else: canvasPage.reset() canvasPage.empty_cursor() store = [] #Try for a callback from speech recognition try: callback = speech_callback_queue.get(False) #doesn't block callback() except queue.Empty: #raised when queue is empty pass #Update App app.update_idletasks() app.update() sleep(0.01) except TclError: #catch rror raised when attempting to quit break # When everything is done, release the capture video_capture.release() #Stop background threads stop_listening(wait_for_stop=False)
import pygame from pygame import mixer_music import random import math # Initialize the pygame pygame.init() # Create the Screen screen = pygame.display.set_mode((800, 600)) # Create a background & Sound background = pygame.image.load('background.jpg') mixer_music.load('backgroundmusic.wav') mixer_music.play(-1) # Title and Icon pygame.display.set_caption("Space Invaders") icon = pygame.image.load('ufo.png') pygame.display.set_icon(icon) # Player playerImg = pygame.image.load('player.png') playerX = 370 playerY = 480 playerX_change = 0 score = 0
from os import system from pygame import init, mixer, mixer_music #, event # mixer.init() # init() # mixer.music.load('Desafio21.mp3') # mixer.music.play() # event.wait() mixer.init() init() mixer_music.load('Desafio21.mp3') mixer_music.play() system('pause')
interface4.interface1 = interface1 interface4.interface2 = interface2 interface4.interface3 = interface3 interface4.interface4 = interface4 interface4.interface5 = interface5 interface4.interface6 = interface6 interface5.interface1 = interface1 interface5.interface2 = interface2 interface5.interface3 = interface3 interface5.interface4 = interface4 interface5.interface5 = interface5 interface5.interface6 = interface6 interface6.interface1 = interface1 interface6.interface2 = interface2 interface6.interface3 = interface3 interface6.interface4 = interface4 interface6.interface5 = interface5 interface7.interfaceAcceuil = interface1 interface8.interfaceAcceuil = interface1 music.play(-1) #Lancement fen.mainloop() music.stop()