syllabify : prise en compte langues sans espace insécable avant les
[nenuvar.git] / scripts / paroles.py
blobb295bad874ae2ca2efc3c8d88333d7495996f6b4
1 from syllabify import *
3 class Lyricsifier():
4 def __init__(self, language='fr'):
5 self.language = language
7 def read_and_write(self, file):
8 #file = open(filename, 'r')
9 sign_tokenizer = SignTokenizer(language=self.language)
10 syllable_tokenizer = SyllableTokenizerWithWordSeparation()
11 for line in file:
12 verse_match = re.match(r"^%#(\S*) (.*)$", line)
13 if verse_match:
14 # a verse
15 verse = Verse(verse_match.group(2).strip())
16 verse.syllabify(sign_tokenizer, syllable_tokenizer)
17 print(verse.hyphenate(hyphen = " -- ", add_space = True))
18 else:
19 # a LilyPond line
20 print("")
22 if __name__ == '__main__':
23 parser = argparse.ArgumentParser(
24 description='LilPond lyrics generation.',
25 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
26 parser.add_argument(
27 '--language',
28 default='fr',
29 help='verse language (fr, it)')
30 parser.add_argument(
31 'files', metavar='FILE',
32 type=argparse.FileType('r'),
33 nargs='+',
34 help='input files')
35 args = vars(parser.parse_args())
36 for file in args['files']:
37 transformer = Lyricsifier(args['language'])
38 transformer.read_and_write(file)