def test(f_discretization=10, e_discretization=30, indep=False, selection=None, subset=None, corpus=None, smoothing=None, sensitivity=5, segmentation='reasonable'): if not selection: selection = (db.select()) score = db.getScore1(selection) if not corpus: (f, e, m) = tools.chooseFeatures() else: (f, e, m) = tools.loadFeatures(corpus) if m['version'] != sf.version: print("Scorefeatures versions don't match! Corpus version: {0} Scorefeatures version: {1}".format(m['version'], sf.version)) exit(0) if not subset: # Select a subset by hand subset = selectSubset(m['featureset']) print('\n\tPerforming {0}'.format(selection)) print('\tFeatures version: {0}'.format(m['version'])) print('\tFeatureset used: [', end=' ') print(', '.join([m['featureset'][i] for i in subset]), end=' ') print(']') print('\tScorefeatures discretization: {0}\n\tExpression discretization: {1}'.format(f_discretization, e_discretization)) print('\tSensitivity: {0}'.format(sensitivity)) print('\tSmoothing: {0}'.format(smoothing)) print('\tCorpus: {0}\n'.format(corpus)) if indep: hmm = HMM_indep(2, smoothing) else: hmm = HMM(2, smoothing) trainHMM(hmm, f, e, f_discretization, e_discretization, subset=subset, ignore=selection, sensitivity=sensitivity) #trainHMM(hmm, f, e, f_discretization, e_discretization, subset=subset) hmm.storeInfo('hmm2.txt') print("Loading score") melodyscore = Score(score).melody() melody = tools.parseScore(melodyscore) # Segmentate the the score print("Analysing score") if segmentation == 'reasonable': print('Using reasonable segmentation') onset = structure.reasonableSegmentation(melody) elif segmentation == 'new': print('Using new segmentation') onset = structure.newSegmentation(melody) elif segmentation == 'notelevel': print('Using notelevel segmentation') onset = structure.noteLevel(melody) #onset = structure.groupings(structure.list_to_tree(structure.first_order_tree(structure.onset, melody, 0.1)), 1) #namelist = [] #for group in onset: # namelist.append([leaf.name() for leaf in group]) #print namelist (p, expression) = render(melodyscore, onset, hmm, f_discretization, e_discretization, subset, sensitivity=sensitivity) print("Done, resulting expression(with a probability of {1}): {0}".format(expression, p)) performance = perform.perform(score, melodyscore, onset, expression, converter=melody) playPerformance(selection, performance, expression, onset, '{0}_{1}_on_{2}_discret_{3}-{4}_smoothing_{5}'.format(\ selection[0], selection[1], corpus, f_discretization, e_discretization, smoothing))
def loadperformance(): (selection, expression) = tools.loadPerformance() score = db.getScore1(selection) melodyscore = Score(score).melody() melody = tools.parseScore(melodyscore) segmentation = structure.reasonableSegmentation(melody) performance = perform.perform(score, Score(score).melody(), segmentation, expression, converter=melody) seq = Sequencer() seq.play(performance)
def chatbot_response(msg): msg=msg.lower() if msg == "hi": Speak.say("hello how are you") return "hello how are you" elif msg=='good morning' or msg=='good afternoon' or msg=='good night': return time_wish() elif msg=='bye' or msg=='close' or msg=='exit': return bye_wish() else: Speak.say("processing") response=perform.perform(msg) if msg!='None': return response else: Speak.say('I am unable to understand') return 'I am unable to understand'