Skip to content

Commit

Permalink
add author functionnality
Browse files Browse the repository at this point in the history
  • Loading branch information
hairygael authored Dec 15, 2024
1 parent e867829 commit 2570d96
Showing 1 changed file with 101 additions and 46 deletions.
147 changes: 101 additions & 46 deletions services/1_AudioFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --

Expand All @@ -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'):
Expand All @@ -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")
Expand All @@ -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:
Expand All @@ -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")

0 comments on commit 2570d96

Please sign in to comment.