@@ -2026,7 +2026,7 @@ class TalkingHead {
20262026 // Classifiers
20272027 const dividersSentence = / [ ! \. \? \n \p{ Extended_Pictographic} ] / ug;
20282028 const dividersWord = / [ ] / ug;
2029- const speakables = / [ \p{ L} \p{ N} , \. ' ! € \$ \+ \- % & \? ] / ug;
2029+ const speakables = / [ \p{ L} \p{ N} , \. ' ! € \$ \+ \- – — % & \? ] / ug;
20302030 const emojis = / [ \p{ Extended_Pictographic} ] / ug;
20312031 const lipsyncLang = opt . lipsyncLang || this . avatar . lipsyncLang || this . opt . lipsyncLang ;
20322032
@@ -2518,14 +2518,33 @@ class TalkingHead {
25182518 const audio = await this . audioCtx . decodeAudioData ( buf ) ;
25192519 this . speakWithHands ( ) ;
25202520
2521+ // Workaround for Google TTS not providing all timepoints
2522+ const times = [ 0 ] ;
2523+ let markIndex = 0 ;
2524+ line . text . forEach ( ( x , i ) => {
2525+ if ( i > 0 ) {
2526+ let ms = times [ times . length - 1 ] ;
2527+ if ( data . timepoints [ markIndex ] ) {
2528+ ms = data . timepoints [ markIndex ] . timeSeconds * 1000 ;
2529+ if ( data . timepoints [ markIndex ] . markName === "" + x . mark ) {
2530+ markIndex ++ ;
2531+ }
2532+ }
2533+ times . push ( ms ) ;
2534+ }
2535+ } ) ;
2536+
2537+ console . log ( times ) ;
2538+
25212539 // Word-to-audio alignment
25222540 const timepoints = [ { mark : 0 , time : 0 } ] ;
2523- data . timepoints . forEach ( ( x , i ) => {
2524- const time = x . timeSeconds * 1000 ;
2525- let prevDuration = time - timepoints [ i ] . time ;
2526- if ( prevDuration > 150 ) prevDuration - 150 ; // Trim out leading space
2527- timepoints [ i ] . duration = prevDuration ;
2528- timepoints . push ( { mark : parseInt ( x . markName ) , time : time } ) ;
2541+ times . forEach ( ( x , i ) => {
2542+ if ( i > 0 ) {
2543+ let prevDuration = x - times [ i - 1 ] ;
2544+ if ( prevDuration > 150 ) prevDuration - 150 ; // Trim out leading space
2545+ timepoints [ i - 1 ] . duration = prevDuration ;
2546+ timepoints . push ( { mark : i , time : x } ) ;
2547+ }
25292548 } ) ;
25302549 let d = 1000 * audio . duration ; // Duration in ms
25312550 if ( d > this . opt . ttsTrimEnd ) d = d - this . opt . ttsTrimEnd ; // Trim out silence at the end
@@ -3116,6 +3135,12 @@ class TalkingHead {
31163135 this . gestureTimeout = null ;
31173136 }
31183137
3138+ // Stop talking hands animation
3139+ let ndx = this . animQueue . findIndex ( y => y . template . name === "talkinghands" ) ;
3140+ if ( ndx !== - 1 ) {
3141+ this . animQueue [ ndx ] . ts = this . animQueue [ ndx ] . ts . map ( x => 0 ) ;
3142+ }
3143+
31193144 // Set gesture
31203145 this . gesture = this . propsToThreeObjects ( g ) ;
31213146 if ( mirror ) {
0 commit comments