home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / lib / duration.scm < prev    next >
Text File  |  1999-05-30  |  7KB  |  197 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;                                                                       ;;
  3. ;;;                Centre for Speech Technology Research                  ;;
  4. ;;;                     University of Edinburgh, UK                       ;;
  5. ;;;                       Copyright (c) 1996,1997                         ;;
  6. ;;;                        All Rights Reserved.                           ;;
  7. ;;;                                                                       ;;
  8. ;;;  Permission is hereby granted, free of charge, to use and distribute  ;;
  9. ;;;  this software and its documentation without restriction, including   ;;
  10. ;;;  without limitation the rights to use, copy, modify, merge, publish,  ;;
  11. ;;;  distribute, sublicense, and/or sell copies of this work, and to      ;;
  12. ;;;  permit persons to whom this work is furnished to do so, subject to   ;;
  13. ;;;  the following conditions:                                            ;;
  14. ;;;   1. The code must retain the above copyright notice, this list of    ;;
  15. ;;;      conditions and the following disclaimer.                         ;;
  16. ;;;   2. Any modifications must be clearly marked as such.                ;;
  17. ;;;   3. Original authors' names are not deleted.                         ;;
  18. ;;;   4. The authors' names are not used to endorse or promote products   ;;
  19. ;;;      derived from this software without specific prior written        ;;
  20. ;;;      permission.                                                      ;;
  21. ;;;                                                                       ;;
  22. ;;;  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        ;;
  23. ;;;  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ;;
  24. ;;;  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ;;
  25. ;;;  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     ;;
  26. ;;;  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ;;
  27. ;;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ;;
  28. ;;;  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ;;
  29. ;;;  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ;;
  30. ;;;  THIS SOFTWARE.                                                       ;;
  31. ;;;                                                                       ;;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;;
  34. ;;;  Basic Duration module which will call appropriate duration
  35. ;;;  (C++) modules based on set parameter
  36. ;;;
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38.  
  39. ;;;  These modules should predict intonation events/labels
  40. ;;;  based on information in the phrase and word streams
  41.  
  42. (define (Duration utt)
  43. "(Duration utt)
  44. Predict segmental durations using Duration_Method defined in Parameters.
  45. Four methods are currently available: averages, Klatt rules, CART tree
  46. based, and fixed duration."
  47.   (let ((rval (apply_method 'Duration_Method utt)))
  48.     (cond
  49.      (rval rval) ;; new style
  50.      ;; 1.1.1 voices still use other names
  51.      ((eq 'Averages (Parameter.get 'Duration_Method))
  52.       (Duration_Averages utt))
  53.      ((eq 'Klatt (Parameter.get 'Duration_Method))
  54.       (Duration_Klatt utt))
  55.      ((eq 'Tree_ZScores (Parameter.get 'Duration_Method))
  56.       (Duration_Tree_ZScores utt))
  57.      ((eq 'Tree (Parameter.get 'Duration_Method))
  58.       (Duration_Tree utt))
  59.      (t
  60.       (Duration_Default utt)))))
  61.  
  62. (define (Duration_LogZScores utt)
  63. "(Duration_LogZScores utt)
  64. Predicts duration to segments using the CART tree in duration_logzscore_tree
  65. and duration_logzscore_tree_silence which produces a zscore of the log
  66. duration.  The variable duration_logzscore_ph_info contains (log) means
  67. and std for each phone in the set."
  68.   (let ((silence (car (car (cdr (assoc 'silences (PhoneSet.description))))))
  69.     ldurinfo)
  70.     (mapcar
  71.      (lambda (s)
  72.        (if (string-equal silence (item.name s))
  73.        (set! ldurinfo
  74.          (wagon s duration_logzscore_tree_silence))
  75.        (set! ldurinfo
  76.          (wagon s duration_logzscore_tree)))
  77.        (set! dur (exp (duration_unzscore 
  78.                (item.name s)
  79.                (car (last ldurinfo))
  80.                duration_logzscore_ph_info)))
  81.        (set! dur (* dur (duration_find_stretch s)))
  82.        (item.set_feat 
  83.     s "end" (+ dur (item.feat s "start_segment"))))
  84.      (utt.relation.items utt 'Segment))
  85.     utt))
  86.  
  87. (define (duration_unzscore phname zscore table)
  88. "(duration_unzscore phname zscore table)
  89. Look up phname in table and convert xscore back to absolute domain."
  90.   (let ((phinfo (assoc phname table))
  91.     mean std)
  92.     (if phinfo
  93.     (begin
  94.       (set! mean (car (cdr phinfo)))
  95.       (set! std (car (cdr (cdr phinfo)))))
  96.     (begin
  97.       (format t "Duration: unzscore no info for %s\n" phname)
  98.       (set! mean 0.100)
  99.       (set! std 0.25)))
  100.     (+ mean (* zscore std))))
  101.  
  102. (define (duration_find_stretch seg)
  103. "(duration_find_stretch utt seg)
  104. Find any relavant duration stretch."
  105.   (let ((global (Parameter.get 'Duration_Stretch))
  106.     (local (item.feat
  107.         seg "R:SylStructure.parent.parent.R:Token.parent.dur_stretch")))
  108.     (if (or (not global)
  109.         (equal? global 0.0))
  110.     (set! global 1.0))
  111.     (if (string-equal local 0.0)
  112.     (set! local 1.0))
  113.     (* global local)))
  114.  
  115. ;; These provide lisp level functions, some of which have
  116. ;; been converted in C++ (in festival/src/modules/base/ff.cc)
  117. (define (onset_has_ctype seg type)
  118.   ;; "1" if onset contains ctype
  119.   (let ((syl (item.relation.parent seg 'SylStructure)))
  120.     (if (not syl)
  121.     "0" ;; a silence 
  122.     (let ((segs (item.relation.daughters syl 'SylStructure))
  123.           (v "0"))
  124.       (while (and segs 
  125.               (not (string-equal 
  126.                 "+" 
  127.                 (item.feat (car segs) "ph_vc"))))
  128.          (if (string-equal 
  129.               type
  130.               (item.feat (car segs) "ph_ctype"))
  131.              (set! v "1"))
  132.          (set! segs (cdr segs)))
  133.       v))))
  134.  
  135. (define (coda_has_ctype seg type)
  136.   ;; "1" if coda contains ctype
  137.   (let ((syl (item.relation.parent seg 'SylStructure)))
  138.     (if (not syl)
  139.     "0" ;; a silence 
  140.     (let ((segs (reverse (item.relation.daughters
  141.                   syl 'SylStructure)))
  142.           (v "0"))
  143.       (while (and segs 
  144.               (not (string-equal 
  145.                 "+" 
  146.                 (item.feat (car segs) "ph_vc"))))
  147.          (if (string-equal 
  148.               type
  149.               (item.feat (car segs) "ph_ctype"))
  150.              (set! v "1"))
  151.          (set! segs (cdr segs)))
  152.       v))))
  153.  
  154. (define (onset_stop seg)
  155.   (onset_has_ctype seg "s"))
  156. (define (onset_fric seg)
  157.   (onset_has_ctype seg "f"))
  158. (define (onset_nasal seg)
  159.   (onset_has_ctype seg "n"))
  160. (define (onset_glide seg)
  161.   (let ((l (onset_has_ctype seg "l")))
  162.     (if (string-equal l "0")
  163.     (onset_has_ctype seg "r")
  164.     "1")))
  165. (define (coda_stop seg)
  166.   (coda_has_ctype seg "s"))
  167. (define (coda_fric seg)
  168.   (coda_has_ctype seg "f"))
  169. (define (coda_nasal seg)
  170.   (coda_has_ctype seg "n"))
  171. (define (coda_glide seg)
  172.   (let ((l (coda_has_ctype seg "l")))
  173.     (if (string-equal l "0")
  174.     (coda_has_ctype seg "r")
  175.     "1")))
  176.  
  177. (define (Unisyn_Duration utt)
  178.   "(UniSyn_Duration utt)
  179. predicts Segment durations is some speficied way but holds the
  180. result in a way necessary for other Unisyn code."
  181.   (let ((end 0))
  182.     (mapcar
  183.      (lambda (s)
  184.        (item.get_utt s)
  185.        (let ((dur (wagon_predict s duration_cart_tree)))
  186.      (set! dur (* (Parameter.get 'Duration_Stretch) dur))
  187.      (set! end (+ dur end))
  188.      (item.set_feat s "target_dur" dur)
  189.      (item.set_function s "start" "unisyn_start")
  190.      (item.set_feat s "end" end)
  191.      (item.set_feat s "dur" dur)
  192.      ))
  193.      (utt.relation.items utt 'Segment))
  194.     utt))
  195.  
  196. (provide 'duration)
  197.