-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtestLyricsAlign.py
More file actions
executable file
·189 lines (134 loc) · 7.7 KB
/
testLyricsAlign.py
File metadata and controls
executable file
·189 lines (134 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Copyright (C) 2014-2017 Music Technology Group - Universitat Pompeu Fabra
#
# This file is part of AlignmentDuration: tool for Lyrics-to-audio alignment with syllable duration modeling
#
# AlignmentDuration is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the Affero GNU General Public License
# version 3 along with this program. If not, see http://www.gnu.org/licenses/
'''
Created on Jan 13, 2016
@author: joro
'''
import os
import sys
import json
import urllib2
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../for_makam'))
from src.for_makam.MakamRecording import parseSectionLinks
from src.align.ScoreSection import ScoreSection
from src.for_makam.MakamScore import loadMakamScore2
from src.align.LyricsAligner import LyricsAligner, extendSectionLinksSelectedSections,\
stereoToMono, loadMakamRecording
currDir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) )
WITH_SECTION_ANNOTATIONS = 1
from src.align.ParametersAlgo import ParametersAlgo
def prepare_for_makam_recording(sectionMetadataURI, sectionLinksSourceURI, audioFileURI):
'''
convenience method
'''
with open(sectionLinksSourceURI) as f:
sectionLinksDict = json.load(f)
with open(sectionMetadataURI) as f2:
sectionMetadataDict = json.load(f2)
### for Juanjos pitch
# extractedPitch = os.path.splitext(audioFileURI)[0] + '.pitch'
# with open(extractedPitch) as f:
# extractedPitchList = json.load(f)
extractedPitchList = None
audioFileURI = stereoToMono(audioFileURI)
return audioFileURI, sectionMetadataDict, sectionLinksDict, extractedPitchList
def testLyricsAlign():
ParametersAlgo.FOR_MAKAM = 1
# test with section links. polyphonic
symbtrtxtURI = os.path.join( currDir, '../example/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci.txt')
sectionMetadataURI = os.path.join( currDir, '../example/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci.sectionsMetadata.json' )
sectionLinksSourceURI = os.path.join( currDir, '../example/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci/18_Munir_Nurettin_Selcuk_-_Gel_Guzelim_Camlicaya/18_Munir_Nurettin_Selcuk_-_Gel_Guzelim_Camlicaya.sectionLinks.json' )
sectionAnnosSourceURI = os.path.join( currDir, '../example/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci/18_Munir_Nurettin_Selcuk_-_Gel_Guzelim_Camlicaya/727cff89-392f-4d15-926d-63b2697d7f3f.json')
audioFileURI = os.path.join( currDir, '../example/nihavent--sarki--aksak--gel_guzelim--faiz_kapanci/18_Munir_Nurettin_Selcuk_-_Gel_Guzelim_Camlicaya/18_Munir_Nurettin_Selcuk_-_Gel_Guzelim_Camlicaya.wav')
# # test of audio working
# URL = 'http://dunya.compmusic.upf.edu/document/by-id/727cff89-392f-4d15-926d-63b2697d7f3f/wav?v=0.5&subtype=wave'
# fetchFileFromURL(URL, audioFileURI)
musicbrainzid = '727cff89-392f-4d15-926d-63b2697d7f3f'
ParametersAlgo.POLYPHONIC = 1
ParametersAlgo.WITH_ORACLE_ONSETS = -1
ParametersAlgo.WITH_ORACLE_PHONEMES = 0
ParametersAlgo.WITH_DURATIONS = 1
##################################################### test with section anno and acapella
# On kora.s.upf.edu
# ParametersAlgo.PATH_TO_HCOPY = '/homedtic/georgid/htkBuilt/bin/HCopy'
symbtrtxtURI = os.path.join( currDir,'../example/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi.txt')
sectionMetadataURI = os.path.join( currDir, '../example/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi.sectionsMetadata.json' )
sectionAnnosSourceURI = os.path.join( currDir, '../example/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi/567b6a3c-0f08-42f8-b844-e9affdc9d215.json' )
audioFileURI = os.path.join( currDir, '../example/nihavent--sarki--kapali_curcuna--kimseye_etmem--kemani_sarkis_efendi/02_Kimseye.wav')
musicbrainzid = '567b6a3c-0f08-42f8-b844-e9affdc9d215'
ParametersAlgo.POLYPHONIC = 0
ParametersAlgo.WITH_ORACLE_ONSETS = -1
ParametersAlgo.DETECTION_TOKEN_LEVEL= 'phonemes'
ParametersAlgo.DETECTION_TOKEN_LEVEL= 'words'
ParametersAlgo.WITH_ORACLE_PHONEMES = 0
ParametersAlgo.WITH_DURATIONS = 0
if WITH_SECTION_ANNOTATIONS:
sectionLinksSourceURI = sectionAnnosSourceURI
audioFileURI, sectionMetadataDict, sectionLinksDict, extractedPitchList = prepare_for_makam_recording(sectionMetadataURI, sectionLinksSourceURI, audioFileURI)
recording = loadMakamRecording(musicbrainzid, audioFileURI, symbtrtxtURI, sectionMetadataDict, sectionLinksDict, WITH_SECTION_ANNOTATIONS)
la = LyricsAligner(recording, WITH_SECTION_ANNOTATIONS, ParametersAlgo.PATH_TO_HCOPY)
outputDir = os.path.join(currDir, '../example/output/')
noteOnsetAnnotationDir = '/Users/joro/Downloads/ISTANBULSymbTr2/'
la.alignRecording( extractedPitchList, outputDir)
#### results
sectionDetectedList = []
if WITH_SECTION_ANNOTATIONS:
sectionLinks = la.recording.sectionAnnos
else:
sectionLinks = la.recording.sectionLinks
for sectionLink in sectionLinks:
if hasattr(sectionLink, 'detectedTokenList'):
sectionDetectedList.append(sectionLink.detectedTokenList)
ret = {'alignedLyricsSyllables':{}, 'sectionlinks':{} }
ret['alignedLyricsSyllables'] = sectionDetectedList
ret['sectionlinks'] = sectionLinksDict
print ret
la.evalAccuracy(ParametersAlgo.EVAL_LEVEL)
def testExtendSectionLinksSelectedSections():
'''
test if extending a sections Links file works well
extendSectionLinksSelectedSections(sectionLinksDict, sectionLinks)
'''
sectionLinks = parseSectionLinks(sectionLinksDict)
makamScore = loadMakamScore2(symbtrtxtURI, sectionMetadataDict )
# changes one test section link as if it were aligned
testSectionLink = sectionLinks[1]
probabaleSections = makamScore.getProbableSectionsForMelodicStructure(testSectionLink)
selectedSection = ScoreSection('blah', 1, 20, 'B2', 'B1')
selectedSectionsSameLyrics = makamScore.getSectionsSameLyrics( selectedSection, probabaleSections)
testSectionLink.setSelectedSections(selectedSectionsSameLyrics)
extendSectionLinksSelectedSections(sectionLinksDict, sectionLinks)
print sectionLinksDict
# def testDecoding():
#
# lyricsWithModels = LyricsWithModels(lyrics, htkParser, ParametersAlgo.DEVIATION_IN_SEC, ParametersAlgo.WITH_PADDED_SILENCE)
# decoder = Decoder(lyricsWithModels, URIRecordingChunkResynthesizedNoExt, alpha)
def fetchFileFromURL(URL, outputFileURI):
print "fetching file from URL {} ... ".format(URL)
try:
response = urllib2.urlopen(URL)
a = response.read()
except Exception:
"...maybe URL has changed"
with open(outputFileURI,'w') as f:
f.write(a)
if __name__ == '__main__':
testLyricsAlign()
# testLyricsAlignOracle()
# testExtendSectionLinksSelectedSections()
# testMakamRecording()