From 7b5f736bfc0dab378262ba0880f11e3cd6882fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Wikle=20DUBARD?= <loic97429@gmail.com> Date: Sun, 29 Sep 2019 18:54:05 +0200 Subject: [PATCH] =?UTF-8?q?lecteur=20de=20musique=20int=C3=A9gr=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jarvis.py | 80 +++++++++++++++++++-------- __pycache__/myimports.cpython-37.pyc | Bin 3310 -> 3171 bytes myimports.py | 3 + 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/Jarvis.py b/Jarvis.py index 4970f83..cf37bbb 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 GIT binary patch delta 667 zcmaDS`B*~TiI<m)fq{Wx>4^!kZ+I9O9)mbA%+0{S;K0DZP;9eNeGy|lLyAl<W0YYE zPn1!LY?N_|T$D))LzHO>LzGzxLzH=ne2PLQW0XaTVv14=L#o9B%Y_Us49$#DRw>F+ z)+x$SHYv(cwkgU{b}1?;swrye%u)6!>M0s2nkic8EKv?A+9^6Ix+!`o`Y8q}hABoV z#wjK#rs>>Kj_wR8W+~<hEet8<sZPzzQO+qADV8k^Q7$P~Db_6vQLZVB!3>%<oAa11 zGcv76ob1eEEgr>^T2@pU#g<l-n3tTI4)M|h`^gJglqR2Gsb%A3U|=ZXo$Sr($tXN| zD(i>I)7i8nB~mL=lS@ldixf)p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X0!O7y>ZuMWd85kH!ib|8?lM{=J53jt%lUkBkQXHR^SX7o- z{6&C)fgvqFFBud#d5JlhC5KlQ-{N$wNKP#P2^E1{UL+0jgA9m3xD?C+dF~d6O>TZl lX-=vg3&=eS7#J8h7<m{uAaL>(?lO5sCLEBBMSz8a1pqvT$>IP2 diff --git a/myimports.py b/myimports.py index b99ec3f..ec7080a 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): -- GitLab