def categorizeByLanguage(score): ly = text.assembleLyrics(score) if not len(ly): return (True, "no_lyrics") lang = langid.classify(ly) if lang: return True, lang[0] else: return False, ""
def simple4d(): # question 11: Assemble syllables into words for some vocal text. import webbrowser from music21 import converter from music21 import text for part in music21.parse('d:/web/eclipse/music21misc/musicxmlLib/Binchois.xml'): lyrics = text.assembleLyrics(part) if 'exultavit' in lyrics: print(lyrics) webbrowser.open('http://www.google.com/search?&q=' + lyrics)
def simple4d(): ''' question 11: Assemble syllables into words for some vocal text. music21 extension: then Google the lyrics if they contain the word exultavit ''' import webbrowser from music21 import text for part in converter.parse('d:/web/eclipse/music21misc/musicxmlLib/Binchois.xml'): lyrics = text.assembleLyrics(part) if 'exultavit' in lyrics: print(lyrics) webbrowser.open('http://www.google.com/search?&q=' + lyrics)
def identifier(self, data): """Return a unique identifier for an instrument.""" identifier = None if len(text.assembleLyrics(data)) > 0: # lyrics present in part, so assume it's a voice part identifier = "v" else: # lyrics not present in part, so derive identifier from instr name name = data.getInstrument().bestName() for regex, identifier in REGEX_ID_MAP: if re.search(regex, name, re.IGNORECASE): # break on first match break return identifier
def hasLyrics(score): ly = text.assembleLyrics(score) if len(ly): return (True, "has_lyrics") else: return (True, "no_lyrics")