@@ -126,7 +126,7 @@ func PrintError(props S.PrintErrorProps) {
126126 sentry .CaptureException (err )
127127 }
128128 }
129- fmt .Println ( message )
129+ fmt .Printf ( " \n %s \n " , message )
130130 os .Exit (1 )
131131 }
132132}
@@ -245,8 +245,17 @@ var splitExceptions = [][]string{
245245 {".com" , "{{}}com" },
246246}
247247
248- func TransformMsToTimestamp (ms int64 ) string {
249- duration := time .Duration (ms ) * time .Millisecond
248+ func TransformMsToTimestamp (n int64 , showMs bool ) string {
249+ if showMs {
250+ ms := n % 1000
251+ n /= 1000
252+ sec := n % 60
253+ n /= 60
254+ min := n % 60
255+ n = n / 60
256+ return fmt .Sprintf ("%02d:%02d:%02d,%03d" , n , min , sec , ms )
257+ }
258+ duration := time .Duration (n ) * time .Millisecond
250259 return fmt .Sprintf ("%02d:%02d" , int (duration .Minutes ()), int (duration .Seconds ())% 60 )
251260}
252261
@@ -255,27 +264,27 @@ func GetSentenceTimestamps(sentences []string, words []S.SentimentAnalysisResult
255264 timestamps := []string {}
256265 for index , sentence := range sentences {
257266 if index == 0 {
258- timestamps = append (timestamps , TransformMsToTimestamp (* words [0 ].Start ))
267+ timestamps = append (timestamps , TransformMsToTimestamp (* words [0 ].Start , false ))
259268 lastIndex = 0
260269 } else {
261270 sentenceWords := strings .Split (sentence , " " )
262271 for i := lastIndex ; i < len (words ); i ++ {
263272 if strings .Contains (sentence , words [i ].Text ) {
264273 if len (words ) >= i + 2 {
265274 if words [i ].Text == sentenceWords [0 ] && words [i + 1 ].Text == sentenceWords [1 ] && words [i + 2 ].Text == sentenceWords [2 ] {
266- timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start ))
275+ timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start , false ))
267276 lastIndex = i
268277 break
269278 }
270279 } else if len (words ) >= i + 1 {
271280 if words [i ].Text == sentenceWords [0 ] && words [i + 1 ].Text == sentenceWords [1 ] {
272- timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start ))
281+ timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start , false ))
273282 lastIndex = i
274283 break
275284 }
276285 } else {
277286 if words [i ].Text == sentenceWords [0 ] {
278- timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start ))
287+ timestamps = append (timestamps , TransformMsToTimestamp (* words [i ].Start , false ))
279288 lastIndex = i
280289 break
281290 }
@@ -295,11 +304,12 @@ func GetSrtText(words []S.SentimentAnalysisResult) string {
295304 var start string
296305 for _ , word := range words {
297306 if sentence == "" {
298- start = TransformMsToTimestamp (* word .Start )
307+ start = TransformMsToTimestamp (* word .Start , true )
299308 }
300309 sentence += word .Text + " "
301- if strings .Contains (word .Text , "." ) {
302- srtText += fmt .Sprintf ("%d\n %s --> %s\n %s\n \n " , index , start , TransformMsToTimestamp (* word .End ), sentence )
310+ if strings .HasSuffix (word .Text , "." ) {
311+
312+ srtText += fmt .Sprintf ("%d\n %s --> %s\n %s\n \n " , index , start , TransformMsToTimestamp (* word .End , true ), sentence )
303313 sentence = ""
304314 index ++
305315 }
@@ -317,21 +327,21 @@ func GetSentenceTimestampsAndSpeaker(sentences []string, words []S.SentimentAnal
317327 }
318328 if sentence != "" {
319329 if index == 0 {
320- timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [0 ].Start ), fmt .Sprintf ("(Speaker %s)" , words [0 ].Speaker )})
330+ timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [0 ].Start , false ), fmt .Sprintf ("(Speaker %s)" , words [0 ].Speaker )})
321331 lastIndex = 0
322332 } else {
323333 sentenceWords := strings .Split (sentence , " " )
324334 for i := lastIndex ; i < len (words ); i ++ {
325335 if strings .Contains (sentence , words [i ].Text ) {
326336 if len (words ) >= i + 1 {
327337 if words [i ].Text == sentenceWords [0 ] {
328- timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [i ].Start ), fmt .Sprintf ("(Speaker %s)" , words [i ].Speaker )})
338+ timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [i ].Start , false ), fmt .Sprintf ("(Speaker %s)" , words [i ].Speaker )})
329339 lastIndex = i
330340 break
331341 }
332342 } else {
333343 if words [i ].Text == sentenceWords [0 ] && words [i + 1 ].Text == sentenceWords [1 ] {
334- timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [i ].Start ), fmt .Sprintf ("(Speaker %s)" , words [i ].Speaker )})
344+ timestamps = append (timestamps , []string {TransformMsToTimestamp (* words [i ].Start , false ), fmt .Sprintf ("(Speaker %s)" , words [i ].Speaker )})
335345 lastIndex = i
336346 break
337347 }
0 commit comments