Beispiel #1
0
def query(name,artist):
	"""Prints summary of song and returns information necessary for decision tree"""
	keys = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb']
	if name == "" or artist == "":
		display_text("No results for that query. \n")
		return -1
	dict = song_profile(str(name),str(artist))
	if dict != "No results for that query. \n":
		dict2 = gti.get_json(dict['audio_summary']['analysis_url'])
		tempo = dict['audio_summary']['tempo']
		time_sig = dict['audio_summary']['time_signature']
		speechiness = dict['audio_summary']['speechiness']
		artist_name = dict['artist_name']
		song = dict['title']
		key_not_found = False
		try:
			key = keys[dict['audio_summary']['key']]
		except:
			key_not_found = True
			key = 'C'
		duration = dict['audio_summary']['duration']
		loudness = dict['audio_summary']['loudness']
		bpm_range = procinp.bpm_range(dict2['beats'])
		max_bpm_spike = procinp.max_bpm_spike(dict2['beats'])
		num_sections = procinp.num_sections(dict2['sections'])
		num_keys_not_found = False
		try:
			num_keys = procinp.num_keys(dict2['sections'])
		except:
			num_keys_not_found = True
			num_keys = 1
		a = "Song information:\n"
		b = "\t" + song + ", by " + artist_name + "\n"
		c = "\tTime signature: " + str(time_sig)+ "\n"
		d = "\tTempo: " + str(tempo)+ " beats per minute\n"
		e = "\tSpeechiness: " + str(speechiness)+ "\n"
		f = "\tLoudness: " + str(loudness)+ " decibels\n"
		if key_not_found:
			g = "\tKey: " + 'Unknown'+ "\n"
		else:
			g = "\tKey: " + str(key)+ "\n"
		h = "\tDuration: " + str(duration)+ " seconds\n"
		i = "\tTempo Range: "+str(bpm_range)+"\n"
		j = "\tMaximum Tempo Spike: "+str(max_bpm_spike)+"\n"
		k = "\tNumber of Sections: "+str(num_sections)+"\n"
		m = "\n"
		if num_keys_not_found:
			l = "\tNumber of Keys: "+'Unknown'+"\n"
		else:
			l = "\tNumber of Keys: "+str(num_keys)+"\n"
		display_text(a+b+c+d+e+f+g+h+i+j+k+l+m)
		return (dict,dict2)
	else:
		display_text(dict)
		return -1
Beispiel #2
0
def guess(name,artist):
	"""Guesses and displays the genre of the input song"""
	if name == "":
		a = "Please enter a song name. \n"
		display_text(a)
	dict1 = song_profile(str(name),str(artist))
	if dict1 == "No results for that query. \n":
		display_text(dict1)
		return
	dict2 = gti.get_json(dict1["audio_summary"]["analysis_url"])
	#url_dict = {dict1['title']: [dict1['audio_summary']['analysis_url'], dict1['id']]}
	#dict2 = gti.build_json_dict(url_dict)
	result = analys.classify_encapsulated(dict1,dict2,'genre_fit.pkl')
	a = "Genre guess for "+str(dict1['title'])+", by "+str(dict1['artist_name'])+": " + str(result[1]) + "\n"
	b = "\t" + str(round(result[0][0]*100,2)) + "%" + " probability this is EDM.\n"
	c = "\t" + str(round(result[0][1]*100,2)) + "%" + " probability this is Folk.\n"
	d = "\t" + str(round(result[0][2]*100,2)) + "%" + " probability this is Rap.\n\n"
	display_text(a+b+c+d)