Re: duration

Subject: Re: duration
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Wed, 22 Jul 1998 07:28:35 -0500 (CDT)
Jim_Albright@xxxxxxx said:
> 
> <BLOCK>
>     <START-TIME>02:22:00</START-TIME>
>     <END-TIME>2:35:13</END-TIME>
>     <REFERENCE BOOK=ACT CHAPTER=1 VERSE=1 END-CHAPTER=1 END-VERSE=2>
> </REFERENCE>
>     <VOICE>LUKE</VOICE>
>     <TEXT>In my former book, Theophilus, I wrote about all that Jesus 
> began to do and to teach until the day he was taken up to heaven, 
> after giving instructions through the Holy Spirit to the apostles he 
> had chosen.</TEXT>
> </BLOCK>
> 
> 
> Given the above I would like to calculate the duration of the speech. 
> 
> The video is being dubbed and we need to let the translators know how 
> many seconds they have to say the equivalent text.
> 
>     <START-TIME>02:22:00</START-TIME>
>     <END-TIME>2:35:13</END-TIME>
> 
> the format is 
> minutes:seconds:frames 
> 
> where there are 30 frames per second and 60 seconds per minute
> The minutes are not consistently padded --- maximum time will be about 
> 120 minutes -- 
> 
> I would like the results to be like:
> 
> 13.4
> Truncated(or rounded if easier) to one decimal place.
> 
> BTW this is part of the project I needed to get a list of speakers for 
> also.
> 
   Okie... let's give this a try.  How about...

(define duration (lambda (#!optional (nd (current-node)))
  (let ((start (select-elements (children nd) "START-TIME"))
        (end   (select-elements (children nd) "END-TIME")))
       (/ (floor
            (/ (- (frames (data start))
                  (frames (data end)))
               3))
          10))))

(define frames (lambda (str)
  (let* ((sl (string-length str)) (slst (string->list str))
         (fc (- sl (length (member ':' slst))))
         (sc (- sl (length (member ':' (list-tail slst (+ fc 1)))))))
        (+ (* 1800 (string->number (substring str 0 fc)))
           (*   30 (string->number (substring str (+ fc 1) sc)))
           (string->number (substring str (+ sc 1) sl))))))

   The function "duration" takes a node (singleton node list,
actually, as DSSSL doesn't actually work with nodes directly) of
element "BLOCK", or defaults to the current node.  It returns the
duration of that node in seconds, truncated (not rounded) to the
nearest tenth of a second.
   So, you could use this like...

(element BLOCK
   (make paragraph ; use whatever settings you want for properties here
      (literal (data (select-elements (children) "VOICE")) ": ("
               (number->string (duration)) " seconds)")
      (make paragraph-break) ; or however you generate a newline...
      (process-matching-children "TEXT")))

   ...or something like that.

-Brandon :)

PS- I didn't actually test this.  Let me know if you have any problems.


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread
  • duration
    • Jim_Albright - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id SAA12542Tue, 21 Jul 1998 18:22:54 -0400 (EDT)
      • Brandon Ibach - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id IAA00440Wed, 22 Jul 1998 08:31:44 -0400 (EDT) <=