Skip to content
Extraits de code Groupes Projets
Valider 7b5f736b rédigé par Loïc Wikle DUBARD's avatar Loïc Wikle DUBARD
Parcourir les fichiers

lecteur de musique intégré

parent 66a2a525
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -76,14 +76,15 @@ def parle(texte, save=True, lang='fr-CA'): ...@@ -76,14 +76,15 @@ def parle(texte, save=True, lang='fr-CA'):
print(line_no) print(line_no)
# mp3 = mutagen.mp3.MP3('saved_voice/{}.mp3'.format(line_no)) # mp3 = mutagen.mp3.MP3('saved_voice/{}.mp3'.format(line_no))
# frequency = mp3.info.sample_rate # frequency = mp3.info.sample_rate
if pygame.mixer.music.get_busy(): if pygame.mixer.Channel(0).get_busy():
pygame.mixer.music.stop() pygame.mixer.Channel(0).stop()
# pygame.mixer.quit() # pygame.mixer.quit()
# pygame.mixer.init(frequency=frequency) # pygame.mixer.init(frequency=frequency)
try: try:
pygame.mixer.music.load('saved_voice/{}.mp3'.format(line_no)) sound = pygame.mixer.Sound('saved_voice/{}.mp3'.format(line_no))
pygame.mixer.music.play() # pygame.mixer.music.load('saved_voice/{}.mp3'.format(line_no))
pygame.mixer.music.set_endevent() pygame.mixer.Channel(0).play(sound)
pygame.mixer.Channel(0).set_endevent()
except: except:
print("ERROR: can't play audio") print("ERROR: can't play audio")
...@@ -372,30 +373,65 @@ def tests(entre): ...@@ -372,30 +373,65 @@ def tests(entre):
sys.exit() sys.exit()
# gestion de la musique # gestion de la musique
if "play" in entre or "jouede la musique" in entre: '''
os.system("rhythmbox-client --play --shuffle") TODO: pygame music player
process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) mixer_1 = pygame.mixer.Channel(1)
stdout, stderr = process.communicate() sound = pygame.mixer.Sound(filename)
parle("j'ai lancé " + stdout.decode(), False) 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: if "pause" in entre:
os.system("rhythmbox-client --pause") # os.system("rhythmbox-client --pause")
pygame.mixer.Channel(1).pause()
parle("pause") parle("pause")
if "musique suivante" in entre: 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: 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: if "nom de la musique" in entre:
process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE) # process = Popen(["rhythmbox-client", "--print-playing"], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate() # stdout, stderr = process.communicate()
parle(stdout.decode(), False) parle("j'ai lancé " + playlist_text[indice_sound], False)
# gestion du volume # gestion du volume
if "monte" in entre and any(e in entre for e in ["son", "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("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"]): if "baisse" in entre and any(e in entre for e in ["son", "volume"]):
# os.system("pactl -- set-sink-volume 0 -10%") # 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 # éteind le pc
# if "eteint" in entre and "ordinateur" in entre: # Eteint l'ordinateur # if "eteint" in entre and "ordinateur" in entre: # Eteint l'ordinateur
...@@ -468,11 +504,11 @@ def tests(entre): ...@@ -468,11 +504,11 @@ def tests(entre):
if __name__ == "__main__": if __name__ == "__main__":
parle("Bonjour ! " + random.choice(["", "Vous allez bien aujourd'hui ?"])) 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 currently_playing = get_busy
"""boucle principale""" """boucle principale"""
while True: 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 # 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 # end_event = pygame.mixer.music.get_endevent() # booléen indique si l'ia a fini de parler
currently_playing = get_busy currently_playing = get_busy
...@@ -490,9 +526,9 @@ if __name__ == "__main__": ...@@ -490,9 +526,9 @@ if __name__ == "__main__":
if currently_playing: if currently_playing:
print('[!]talkin...', end='') 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: if currently_playing and 'stop' in entre:
pygame.mixer.music.stop() pygame.mixer.Channel(0).stop()
elif deverouillage(entre): elif deverouillage(entre):
tests(entre) tests(entre)
Aucun aperçu pour ce type de fichier
...@@ -96,6 +96,9 @@ fonctionnalites = [ ...@@ -96,6 +96,9 @@ fonctionnalites = [
'jouer de la musique' 'jouer de la musique'
# 'traduire un texte ou un mot dans une autre langue' # '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): class BreakoutException(Exception):
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter