Add fuzzy and text-classification light model #1
3 changed files with 42 additions and 21 deletions
|
@ -4,10 +4,12 @@ from rapidfuzz import process, fuzz, utils
|
||||||
ROOMS = ["cuisine", "salon", "chambre", "bureau"]
|
ROOMS = ["cuisine", "salon", "chambre", "bureau"]
|
||||||
|
|
||||||
|
|
||||||
MUSIQUE_GENRE_SHORT = ["synthpop", "jazz classique", "jazz manouche", "classique", "rock", "jazz", "blues", "film", "francaise", "pop", "reggae", "folk",
|
MUSIQUE_GENRE_SHORT = ["synthpop", "jazz classique", "jazz manouche", "latine", "classique", "rock", "jazz",
|
||||||
|
"blues", "film", "francaise", "pop", "reggae", "folk",
|
||||||
"électro", "punk", "corse", "arabe", "persane", "piano", "rap", "slam"]
|
"électro", "punk", "corse", "arabe", "persane", "piano", "rap", "slam"]
|
||||||
|
|
||||||
MUSIQUE_GENRE_LONG = ["synthpop", "jazz classique", "jazz manouche", "classique", "rock", "jazz", "blues", "musique de film", "chanson francaise", "pop", "reggae", "folk",
|
MUSIQUE_GENRE_LONG = ["synthpop", "jazz classique", "jazz manouche", "chanson latine", "classique", "rock", "jazz",
|
||||||
|
"blues", "musique de film", "chanson francaise", "pop", "reggae", "folk",
|
||||||
"électro", "punk", "chanson corse", "chanson arabe", "chanson persane", "piano", "rap", "slam", "chanson classique"]
|
"électro", "punk", "chanson corse", "chanson arabe", "chanson persane", "piano", "rap", "slam", "chanson classique"]
|
||||||
|
|
||||||
|
|
||||||
|
|
54
src/mpd.py
54
src/mpd.py
|
@ -2,17 +2,18 @@ import logging
|
||||||
import random
|
import random
|
||||||
from mpd import MPDClient
|
from mpd import MPDClient
|
||||||
|
|
||||||
|
|
||||||
class Mpd():
|
class Mpd():
|
||||||
|
|
||||||
def __init__(self,ip, yoda):
|
def __init__(self, ip, yoda):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.port = 6600
|
self.port = 6600
|
||||||
self.client = MPDClient() # create client object
|
self.client = MPDClient() # create client object
|
||||||
self.client.timeout = 10 # network timeout in seconds (floats allowed), default: None
|
# network timeout in seconds (floats allowed), default: None
|
||||||
|
self.client.timeout = 10
|
||||||
self.client.idletimeout = None
|
self.client.idletimeout = None
|
||||||
self.yoda = yoda
|
self.yoda = yoda
|
||||||
|
|
||||||
|
|
||||||
self.client.connect(ip, self.port)
|
self.client.connect(ip, self.port)
|
||||||
logging.debug(self.client.mpd_version)
|
logging.debug(self.client.mpd_version)
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
@ -36,11 +37,12 @@ class Mpd():
|
||||||
logging.debug('Listing '+self.normalize_genre(genre))
|
logging.debug('Listing '+self.normalize_genre(genre))
|
||||||
try:
|
try:
|
||||||
# todo: select only one album instead of the artist
|
# todo: select only one album instead of the artist
|
||||||
list_album = self.client.lsinfo("Files/Genres/"+self.normalize_genre(genre))
|
list_album = self.client.lsinfo(
|
||||||
|
"Subsonic/Genre/"+self.normalize_genre(genre))
|
||||||
except:
|
except:
|
||||||
list_album = []
|
list_album = []
|
||||||
|
|
||||||
if(list_album):
|
if (list_album):
|
||||||
random_album = random.choice(list_album)["directory"]
|
random_album = random.choice(list_album)["directory"]
|
||||||
self.play_album(random_album)
|
self.play_album(random_album)
|
||||||
else:
|
else:
|
||||||
|
@ -49,7 +51,7 @@ class Mpd():
|
||||||
self.client.close()
|
self.client.close()
|
||||||
self.client.disconnect()
|
self.client.disconnect()
|
||||||
|
|
||||||
def play_album(self,directory):
|
def play_album(self, directory):
|
||||||
self.client.stop()
|
self.client.stop()
|
||||||
self.yoda.say("Lancement de "+directory.split('/')[-1])
|
self.yoda.say("Lancement de "+directory.split('/')[-1])
|
||||||
logging.debug('Playing '+directory)
|
logging.debug('Playing '+directory)
|
||||||
|
@ -57,21 +59,35 @@ class Mpd():
|
||||||
self.client.add(directory)
|
self.client.add(directory)
|
||||||
self.client.play(0)
|
self.client.play(0)
|
||||||
|
|
||||||
def normalize_genre(self,genre):
|
def normalize_genre(self, genre):
|
||||||
return NORMALIZED_GENRE[genre.lower()]
|
return NORMALIZED_GENRE[genre.lower()]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NORMALIZED_GENRE = {
|
NORMALIZED_GENRE = {
|
||||||
'classique': 'classique',
|
'classique': 'Classique',
|
||||||
'musique classique': 'classique',
|
'musique classique': 'Classique',
|
||||||
'jazz': 'jazz',
|
'jazz': 'Jazz',
|
||||||
'chanson française': 'chanson francaise',
|
'chanson française': 'Chanson Francaise',
|
||||||
'chanson anglaise': 'chanson anglaise',
|
'francaise': 'Chanson Francaise',
|
||||||
'musique de film': 'musique de film',
|
'chanson anglaise': 'Chanson anglaise',
|
||||||
'électro': 'electro',
|
'reggae': 'Reggae',
|
||||||
'musique électronique': 'electro',
|
'folk': 'Folk',
|
||||||
'rock': 'rock',
|
'électro': 'Electro',
|
||||||
'pop': 'pop',
|
'musique électronique': 'Electro',
|
||||||
'chanson latine': 'chanson latine',
|
'punk': 'Punk',
|
||||||
|
'rock': 'Rock',
|
||||||
|
'pop': 'Pop',
|
||||||
|
'latine': 'Latin',
|
||||||
|
'arabe': 'Arabic',
|
||||||
|
'corse': 'Chants Corse',
|
||||||
|
'persane': 'Chanson Persane',
|
||||||
|
'piano': 'Piano',
|
||||||
|
'rap': 'Rap',
|
||||||
|
'slam': 'Slam',
|
||||||
|
'synthpop': 'Synthpop',
|
||||||
|
'jazz classique': 'Classique Jazz',
|
||||||
|
'jazz manouche': 'Jazz Manouche',
|
||||||
|
'blues': 'Blues',
|
||||||
|
'film': 'Soundtrack',
|
||||||
|
'musique de film': 'Soundtrack',
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,9 @@ class Ratatouille():
|
||||||
return self.light_on_single(payload['intentArg'][0])
|
return self.light_on_single(payload['intentArg'][0])
|
||||||
elif command == "LightOff":
|
elif command == "LightOff":
|
||||||
return self.light_off_single(payload['intentArg'][0])
|
return self.light_off_single(payload['intentArg'][0])
|
||||||
|
elif command == "PlayMusicGenre":
|
||||||
|
return self.play_genre(payload['intentArg'][0])
|
||||||
|
return '42'
|
||||||
|
|
||||||
def weather_query(self, entities):
|
def weather_query(self, entities):
|
||||||
if any(a in entities['B-weather_descriptor'] for a in TEMPERATURE_KEYWORD):
|
if any(a in entities['B-weather_descriptor'] for a in TEMPERATURE_KEYWORD):
|
||||||
|
|
Loading…
Add table
Reference in a new issue