diff --git a/Jarvis.py b/Jarvis.py index 4970f83f01b80343352f5065e68f6800184744cb..cf37bbb2b228939290c0f12e509abe27db8ce5ec 100755 --- a/Jarvis.py +++ b/Jarvis.py @@ -76,14 +76,15 @@ def parle(texte, save=True, lang='fr-CA'): print(line_no) # mp3 = mutagen.mp3.MP3('saved_voice/{}.mp3'.format(line_no)) # frequency = mp3.info.sample_rate - if pygame.mixer.music.get_busy(): - pygame.mixer.music.stop() + if pygame.mixer.Channel(0).get_busy(): + pygame.mixer.Channel(0).stop() # pygame.mixer.quit() # pygame.mixer.init(frequency=frequency) try: - pygame.mixer.music.load('saved_voice/{}.mp3'.format(line_no)) - pygame.mixer.music.play() - pygame.mixer.music.set_endevent() + sound = pygame.mixer.Sound('saved_voice/{}.mp3'.format(line_no)) + # pygame.mixer.music.load('saved_voice/{}.mp3'.format(line_no)) + pygame.mixer.Channel(0).play(sound) + pygame.mixer.Channel(0).set_endevent() except: print("ERROR: can't play audio") @@ -372,30 +373,65 @@ def tests(entre): sys.exit() # gestion de la musique - if "play" in entre or "jouede la musique" in entre: - os.system("rhythmbox-client --play --shuffle") - process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) - stdout, stderr = process.communicate() - parle("j'ai lancé " + stdout.decode(), False) + ''' + TODO: pygame music player + mixer_1 = pygame.mixer.Channel(1) + sound = pygame.mixer.Sound(filename) + methodes sur mixer_1 : + play(sound) + pause() + unpause() + stop() + fadeout(time) + set_volume(value) + get_volume() + get_busy() + get_sound() + queue(sound) + get_queue() + set_endevent() + get_endevent() + ''' + if "play" in entre or "joue de la musique" in entre or "met de la musique" in entre: + # os.system("rhythmbox-client --play --shuffle") + # process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) + # stdout, stderr = process.communicate() + indice_sound = random.randint(0, len(playlist_sound) - 1) + sound = playlist_sound[indice_sound] + pygame.mixer.Channel(1).play(sound) + parle("j'ai lancé " + playlist_text[indice_sound], False) if "pause" in entre: - os.system("rhythmbox-client --pause") + # os.system("rhythmbox-client --pause") + pygame.mixer.Channel(1).pause() parle("pause") if "musique suivante" in entre: - os.system("rhythmbox-client --next") + # os.system("rhythmbox-client --next") + indice_sound = (indice_sound + 1) % len(playlist_sound) + sound = playlist_sound[indice_sound] + pygame.mixer.Channel(1).play(sound) + parle("j'ai lancé " + playlist_text[indice_sound], False) if "musique precedente" in entre: - os.system("rhythmbox-client --previous") + # os.system("rhythmbox-client --previous") + indice_sound = (indice_sound - 1) % len(playlist_sound) + sound = playlist_sound[indice_sound] + pygame.mixer.Channel(1).play(sound) + parle("j'ai lancé " + playlist_text[indice_sound], False) if "nom de la musique" in entre: - process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) - stdout, stderr = process.communicate() - parle(stdout.decode(), False) + # process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) + # stdout, stderr = process.communicate() + parle("j'ai lancé " + playlist_text[indice_sound], False) # gestion du volume if "monte" in entre and any(e in entre for e in ["son", "volume"]): # os.system("pactl -- set-sink-volume 0 +10%") - os.system("rhythmbox-client --volume-up") + # os.system("rhythmbox-client --volume-up") + pygame.mixer.Channel(1).set_volume(pygame.mixer.Channel(1).get_volume() + 10) + print("[!] music volume :", pygame.mixer.Channel(1).get_volume()) if "baisse" in entre and any(e in entre for e in ["son", "volume"]): # os.system("pactl -- set-sink-volume 0 -10%") - os.system("rhythmbox-client --volume-down") + # os.system("rhythmbox-client --volume-down") + pygame.mixer.Channel(1).set_volume(pygame.mixer.Channel(1).get_volume() + 10) + print("[!] music volume :", pygame.mixer.Channel(1).get_volume()) # éteind le pc # if "eteint" in entre and "ordinateur" in entre: # Eteint l'ordinateur @@ -468,11 +504,11 @@ def tests(entre): if __name__ == "__main__": parle("Bonjour ! " + random.choice(["", "Vous allez bien aujourd'hui ?"])) - get_busy = pygame.mixer.music.get_busy() + get_busy = pygame.mixer.Channel(0).get_busy() currently_playing = get_busy """boucle principale""" while True: - get_busy = pygame.mixer.music.get_busy() + get_busy = pygame.mixer.Channel(0).get_busy() # booléen qui indique si l'ia est en train de parler # end_event = pygame.mixer.music.get_endevent() # booléen indique si l'ia a fini de parler currently_playing = get_busy @@ -490,9 +526,9 @@ if __name__ == "__main__": if currently_playing: print('[!]talkin...', end='') - print('vol:', pygame.mixer.music.get_volume()) + print('vol:', pygame.mixer.Channel(0).get_volume()) if currently_playing and 'stop' in entre: - pygame.mixer.music.stop() + pygame.mixer.Channel(0).stop() elif deverouillage(entre): tests(entre) diff --git a/__pycache__/myimports.cpython-37.pyc b/__pycache__/myimports.cpython-37.pyc index 6bf526abf2063f86d1991d2bc551fd2983835496..c7470415e6c41af67019bc141e60abeb0bbb3361 100644 Binary files a/__pycache__/myimports.cpython-37.pyc and b/__pycache__/myimports.cpython-37.pyc differ diff --git a/myimports.py b/myimports.py index b99ec3fdaa69db677e055b8ff9d9475a6c96a8ef..ec7080a60a9ff9322c156d6e6b7d80f64eae15e9 100644 --- a/myimports.py +++ b/myimports.py @@ -96,6 +96,9 @@ fonctionnalites = [ 'jouer de la musique' # 'traduire un texte ou un mot dans une autre langue' ] +with open("playlist.txt") as f: + playlist_text = f.readlines() +playlist_sound = [pygame.mixer.Sound(sound) for sound in playlist_text] class BreakoutException(Exception):