From 2570d96cec62fa4a92770a33d36d583db9498b25 Mon Sep 17 00:00:00 2001 From: Langevin Gael Date: Sun, 15 Dec 2024 19:41:44 +0100 Subject: [PATCH] add author functionnality --- services/1_AudioFile.py | 147 +++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 46 deletions(-) diff --git a/services/1_AudioFile.py b/services/1_AudioFile.py index e07b95b6..8c166837 100644 --- a/services/1_AudioFile.py +++ b/services/1_AudioFile.py @@ -2,6 +2,7 @@ # 1_AudioFile.py # categories: inmoov2 # more info @: http://myrobotlab.org/service/InMoov +# modif lecagnois le 13/12/2024 pour jukeboxe et radio ######################################### # -- coding: utf-8 -- @@ -21,19 +22,20 @@ def initAudioPlayer(): def onAudioStart(data): try: if i01_ear.listening: - i01_ear.stopListening() + i01_ear.stopListening() except: - print "onAudioStart error" + print("onAudio Start") pass def onAudioEnd(data): try: if not i01_ear.listening: - i01_ear.startListening() + i01_ear.startListening() except: - print "onAudioEnd error" - pass + print("onAudio End") + pass +# Procedure pour le jukebox def playMusic(): if runtime.isStarted('i01.chatBot'): if runtime.isStarted('i01.audioPlayer'): @@ -57,27 +59,35 @@ def playRandomMusic(): i01.warn("i01.chatBot needs to be started") def searchPlay(song): + song = song.decode('utf-8') if runtime.isStarted('i01.chatBot'): if runtime.isStarted('i01.audioPlayer'): initAudioPlayer() global musicList + global pointeur + global lignes_audio if os.path.exists(musicList): - global liste - global pointeur - f = open(musicList, 'r') - liste = f.readlines() - #Remove the first 11 elements of the list - del liste[0:11] + #create a list of songs from the i01.audioPlayer.yml file + lignes_audio = [] + lignes_audio.append("bigin") + with open(musicList, 'r') as f: + for ligne in f: + if( ".mp3" in ligne) or ( ".wav" in ligne): + Mchaine = (ligne.strip().decode('utf-8')).lower() + lignes_audio.append(Mchaine) + lignes_audio.append("eof") + #for result in lignes_audio : + # print(result) i=0 flag =0 # iteration on the list with set up of the chaine - while i <= len(liste)-2 : - var = unicode("".join(liste[i][4:]).rstrip('\n'),'utf-8') + while i <= len(lignes_audio)-1 : + var = ("".join(lignes_audio[i][4:]).rstrip('\n')) if (song.lower() in var) or (song.capitalize() in var): i01_audioPlayer.play(var) pointeur = i flag = 1 - print(var+" Song : "+str(pointeur)) + print("I've found "+var+" Song : "+str(i+1)) i=i+1 if flag == 0 : i01_chatBot.getResponse("DO_NOT_HAVE_SONG") @@ -92,21 +102,26 @@ def searchPlay(song): i01.warn("i01.chatBot needs to be started") def nextPlay(): + #i01_audioPlayer.stop() if runtime.isStarted('i01.chatBot'): if runtime.isStarted('i01.audioPlayer'): initAudioPlayer() global pointeur + global lignes_audio pointeur = pointeur + 1 i01_audioPlayer.stop() - var = unicode("".join(liste[pointeur][4:]).rstrip('\n'),'utf-8') - if 'mp3' or 'wav' in var : + var = unicode("".join(lignes_audio[pointeur][4:]).rstrip('\n'),'utf-8') + print(var+" Song : "+str(pointeur)) + if ("mp3" or "wav") in var : i01_audioPlayer.play(var) print(var+" Song : "+str(pointeur)) - else: + else : i01_chatBot.getResponse("END_PLAYLIST") - pointeur = -1 + pointeur = pointeur-pointeur +1 i01_audioPlayer.stop() - i01_chatBot.getResponse("SYSTEM_NEXT_SONG") + #i01_chatBot.getResponse("SYSTEM_NEXT_SONG") + i01_audioPlayer.play(unicode("".join(lignes_audio[pointeur][4:]).rstrip('\n'),'utf-8')) + print(" start of playlist : "+("".join(lignes_audio[1][4:]).rstrip('\n'))+" Song : "+str(pointeur)) else : i01_AudioPlayer = runtime.start('i01.audioPlayer','AudioFile') else: @@ -116,44 +131,84 @@ def previousPlay(): if runtime.isStarted('i01.chatBot'): if runtime.isStarted('i01.audioPlayer'): initAudioPlayer() - global pointeur + global pointeur + global lignes_audio pointeur = pointeur -1 i01_audioPlayer.stop() - var = unicode("".join(liste[pointeur][4:]).rstrip('\n'),'utf-8') - if 'mp3' or 'wav' in var : + var = unicode("".join(lignes_audio[pointeur][4:]).rstrip('\n'),'utf-8') + #print(var+" Song : "+str(pointeur)) + if ("mp3" or "wav'") in var : i01_audioPlayer.play(var) print(var+" Song : "+str(pointeur)) else: - i01_chatBot.getResponse("END_PLAYLIST") - pointeur = -1 + # sinon arriver au debut de la liste on recommence + i01_chatBot.getResponse("BEGIN_PLAYLIST") + pointeur = pointeur + 1 i01_audioPlayer.stop() - i01_chatBot.getResponse("SYSTEM_NEXT_SONG") + i01_audioPlayer.play(unicode("".join(lignes_audio[pointeur][4:]).rstrip('\n'),'utf-8')) + print(" start of playlist : "+("".join(lignes_audio[1][4:]).rstrip('\n'))+" Song : "+str(pointeur)) + + else : + i01_AudioPlayer = runtime.start('i01.audioPlayer','AudioFile') + else: + i01.warn("i01.chatBot needs to be started") + +def authorPlaylist() : + if runtime.isStarted('i01.chatBot'): + if runtime.isStarted('i01.audioPlayer'): + global musicList + initAudioPlayer() + #create a list of author from the i01.audioPlayer.yml file + lignes_auteur = [] + with open(musicList, 'r') as f: + for ligne in f: + if(".mp3" not in ligne) and ("publishPeakResetDelayMs" not in ligne) and ("playlists" not in ligne) and ("null" not in ligne)\ + and ("false" not in ligne) and ("true" not in ligne) and ("AudioFile" not in ligne) and ("method" not in ligne) and ("myrobotlab" not in ligne)\ + and ("callback" not in ligne) and ("audio" not in ligne) and ("current" not in ligne) and ("peak" not in ligne) and ("listener" not in ligne)and \ + ("volume" not in ligne) and (".wav" not in ligne): + lignes_auteur.append(ligne.strip().decode('utf-8')) + for result in lignes_auteur : + print(result) + for i in range(len(lignes_auteur)): + i01.speakBlocking(u","+lignes_auteur[i]) + f.close() else : i01_AudioPlayer = runtime.start('i01.audioPlayer','AudioFile') else: i01.warn("i01.chatBot needs to be started") + +# radio process def startRadio(station): - if runtime.isStarted("i01.audioPlayer"): - audioPlayer = runtime.getService("i01.audioPlayer") - audiocfg = audioPlayer.getConfig() - print("Radio started") - if audiocfg.stream == 0: - audiocfg.stream = 1 - audioPlayer.save() - audioPlayer.apply(audiocfg) - audioPlayer.broadcastState() - print(station) - audioPlayer.playFile(station) + if runtime.isStarted('i01.chatBot'): + if station[:4].lower() == 'http': + if runtime.isStarted("i01.audioPlayer"): + audioPlayer = runtime.getService("i01.audioPlayer") + audiocfg = audioPlayer.getConfig() + print("Radio started") + if audiocfg.stream == 0: + audiocfg.stream = 1 + audioPlayer.save() + audioPlayer.apply(audiocfg) + audioPlayer.broadcastState() + print(station) + audioPlayer.playFile(station) + else: + i01_chatBot.getResponse("DO_NOT_HAVE_RADIO") + else: + i01.warn("i01.chatBot needs to be started") def stopRadio(): - if runtime.isStarted('i01.audioPlayer'): - audioPlayer = runtime.getService('i01.audioPlayer') - audioPlayer.stop() - print("Radio stopped") - audiocfg = audioPlayer.getConfig() - if audiocfg.stream == 1: - audiocfg.stream = 0 - audioPlayer.save() - audioPlayer.apply(audiocfg) - audioPlayer.broadcastState() + if runtime.isStarted('i01.chatBot'): + if runtime.isStarted('i01.audioPlayer'): + audioPlayer = runtime.getService('i01.audioPlayer') + audioPlayer.stop() + print("Radio stopped") + audiocfg = audioPlayer.getConfig() + if audiocfg.stream == 1: + audiocfg.stream = 1 + audioPlayer.save() + audioPlayer.apply(audiocfg) + audioPlayer.broadcastState() + else: + i01.warn("i01.chatBot needs to be started")