File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,12 +140,6 @@ function initializeKaraoke() {
140140 lyricsEngine . processFinalWords ( ) ;
141141 }
142142
143- // Perform comprehensive score ratification if recognition is enabled
144- if ( isSpeechRecognitionEnabled && lyricsEngine && typeof lyricsEngine . score_ratification === 'function' ) {
145- console . log ( 'Song ended - performing score ratification for all target words' ) ;
146- lyricsEngine . score_ratification ( ) ;
147- }
148-
149143 // Stop speech recognition when song ends
150144 if ( isSpeechRecognitionEnabled && window . SpeechRecognitionModule ) {
151145 console . log ( 'Song ended - stopping speech recognition' ) ;
@@ -167,12 +161,6 @@ function initializeKaraoke() {
167161 lyricsEngine . processFinalWords ( ) ;
168162 }
169163
170- // Perform comprehensive score ratification if recognition is enabled
171- if ( isSpeechRecognitionEnabled && lyricsEngine && typeof lyricsEngine . score_ratification === 'function' ) {
172- console . log ( 'Music ended - performing score ratification for all target words' ) ;
173- lyricsEngine . score_ratification ( ) ;
174- }
175-
176164 // Stop speech recognition when music ends
177165 if ( isSpeechRecognitionEnabled && window . SpeechRecognitionModule ) {
178166 console . log ( 'Music ended - stopping speech recognition' ) ;
Original file line number Diff line number Diff line change @@ -291,10 +291,29 @@ class LyricsEngine {
291291 if ( window . highlightTargetWordInTable ) {
292292 window . highlightTargetWordInTable ( targetWord . id , false ) ;
293293 }
294+
295+ // Check if this was the last target word to complete its timing window
296+ this . checkForRatificationTrigger ( ) ;
294297 }
295298 } ) ;
296299 }
297300
301+ /**
302+ * Check if all target words have completed their timing windows and trigger ratification
303+ */
304+ checkForRatificationTrigger ( ) {
305+ // Check if all target words have finished their listening windows
306+ const allFinished = this . targetWords . every ( targetWord => ! targetWord . listeningActive ) ;
307+
308+ if ( allFinished && this . targetWords . length > 0 ) {
309+ // All target words have completed - trigger ratification if recognition is enabled
310+ if ( window . isSpeechRecognitionEnabled && typeof this . score_ratification === 'function' ) {
311+ console . log ( '🎯 All target words completed - triggering score ratification' ) ;
312+ this . score_ratification ( ) ;
313+ }
314+ }
315+ }
316+
298317 /**
299318 * Calculate the start time of a sentence
300319 * @param {number } sentenceIndex - Index of the sentence
You can’t perform that action at this time.
0 commit comments