home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / lib / pauses.scm < prev    next >
Text File  |  1999-05-30  |  8KB  |  191 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. ;;;  Predicting pause insertion
  35.  
  36. (define (Pauses utt)
  37. "(Pauses utt)                                
  38. Insert pauses where required."
  39.   (let ((rval (apply_method 'Pause_Method utt)))
  40.     (cond
  41.      (rval rval) ;; new style
  42.      (t
  43.       (Classic_Pauses utt)))))
  44.  
  45. (define (Classic_Pauses utt)
  46.   "(Pauses UTT)
  47. Predict pause insertion."
  48.   (let ((words (utt.relation.items utt 'Word)) lastword tpname)
  49.     (if words
  50.     (begin
  51.       (insert_initial_pause utt)   ;; always have a start pause
  52.       (set! lastword (car (last words)))
  53.       (mapcar
  54.        (lambda (w)
  55.          (let ((pbreak (item.feat w "pbreak"))
  56.            (emph (item.feat w "R:Token.parent.EMPH")))
  57.            (cond
  58.         ((or (string-equal "B" pbreak)
  59.              (string-equal "BB" pbreak))
  60.          (insert_pause utt w))
  61. ;        ((string-equal emph "1")
  62. ;         (insert_pause utt w))
  63.         ((equal? w lastword)
  64.          (insert_pause utt w)))))
  65.        words)
  66.       ;; The embarassing bit.  Remove any words labelled as punc or fpunc
  67.       (mapcar
  68.        (lambda (w)
  69.          (let ((pos (item.feat w "pos")))
  70.            (if (or (string-equal "punc" pos)
  71.                (string-equal "fpunc" pos))
  72.            (let ((pbreak (item.feat w "pbreak"))
  73.              (wp (item.relation w 'Phrase)))
  74.              (if (and (string-matches pbreak "BB?")
  75.                   (item.relation.prev w 'Word))
  76.              (item.set_feat 
  77.               (item.relation.prev w 'Word) "pbreak" pbreak))
  78.              (item.relation.remove w 'Word)
  79.              ;; can't refer to w as we've just deleted it
  80.              (item.relation.remove wp 'Phrase)))))
  81.        words)))
  82.   utt))
  83.  
  84. (define (insert_pause utt word)
  85. "(insert_pause UTT WORDITEM)
  86. Insert a silence segment after the last segment in WORDITEM in UTT."
  87.   (let ((lastseg (find_last_seg word))
  88.     (silence (car (car (cdr (car (PhoneSet.description '(silences))))))))
  89.     (if lastseg
  90.     (item.relation.insert 
  91.      lastseg 'Segment (list silence) 'after))))
  92.  
  93. (define (insert_initial_pause utt)
  94. "(insert_initial_pause UTT)
  95. Always have an initial silence if the utterance is non-empty.
  96. Insert a silence segment after the last segment in WORDITEM in UTT."
  97.   (let ((firstseg (car (utt.relation.items utt 'Segment)))
  98.     (silence (car (car (cdr (car (PhoneSet.description '(silences))))))))
  99.     (if firstseg
  100.     (item.relation.insert 
  101.      firstseg 'Segment (list silence) 'before))))
  102.  
  103. (define (find_last_seg word)
  104. ;;; Find the segment that is immediately at this end of this word
  105. ;;; If this word is punctuation it might not have any segments
  106. ;;; so we have to check back until we find a word with a segment in it
  107.   (cond
  108.    ((null word)
  109.     nil)  ;; there are no segs (don't think this can happen)
  110.    (t
  111.     (let ((lsyl (item.relation.daughtern word 'SylStructure)))
  112.     (if lsyl
  113.     (item.relation.daughtern lsyl 'SylStructure)
  114.     (find_last_seg (item.relation.prev word 'Word)))))))
  115.  
  116. (define (Unisyn_Pauses utt)
  117.   "(Unisyn_Pauses UTT)
  118. Predict pause insertion in a Unisyn utterance structure."
  119.   (let ((words (utt.relation.items utt 'Word)) lastword tpname)
  120.     (if words
  121.     (begin
  122.       (us_insert_initial_pause utt)   ;; always have a start pause
  123.       (set! lastword (car (last words)))
  124.       (mapcar
  125.        (lambda (w)
  126.          (let ((pbreak (item.feat w "pbreak"))
  127.            (emph (item.feat w "R:Token.parent.EMPH")))
  128.            (cond
  129.         ((or (string-equal "B" pbreak)
  130.              (string-equal "BB" pbreak))
  131.          (us_insert_pause utt w))
  132. ;        ((string-equal emph "1")
  133. ;         (us_insert_pause utt w))
  134.         ((equal? w lastword)
  135.          (us_insert_pause utt w)))))
  136.        words)
  137.       ;; The embarassing bit.  Remove any words labelled as punc or fpunc
  138.       (mapcar
  139.        (lambda (w)
  140.          (let ((pos (item.feat w "pos")))
  141.            (if (or (string-equal "punc" pos)
  142.                (string-equal "fpunc" pos))
  143.            (let ((pbreak (item.feat w "pbreak"))
  144.              (wp (item.relation w 'Phrase)))
  145.              (if (and (string-matches pbreak "BB?")
  146.                   (item.relation.prev w 'Word))
  147.              (item.set_feat 
  148.               (item.relation.prev w 'Word) "pbreak" pbreak))
  149.              (item.relation.remove w 'Word)
  150.              ;; can't refer to w as we've just deleted it
  151.              (item.relation.remove wp 'Phrase)))))
  152.        words)))
  153.   utt))
  154.  
  155. (define (us_insert_pause utt word)
  156. "(us)insert_pause UTT WORDITEM)
  157. Insert a silence segment after the last segment in WORDITEM in UTT."
  158.   (let ((lastseg (us_find_last_seg word))
  159.     (silence "pau"))
  160.     (if lastseg
  161.     (item.relation.insert 
  162.      lastseg 'Segment (list silence) 'after))))
  163.  
  164. (define (us_insert_initial_pause utt)
  165. "(us_insert_initial_pause UTT)
  166. Always have an initial silence if the utterance is non-empty.
  167. Insert a silence segment after the last segment in WORDITEM in UTT."
  168.   (let ((firstseg (utt.relation.first utt 'Segment))
  169.     (silence "pau"))
  170.     (if firstseg
  171.     (item.relation.insert 
  172.      firstseg 'Segment (list silence) 'before))))
  173.  
  174. (define (us_find_last_seg word)
  175. ;;; Find the segment that is immediately at this end of this word
  176. ;;; If this word is punctuation it might not have any segments
  177. ;;; so we have to check back until we find a word with a segment in it
  178.   (cond
  179.    ((null word)
  180.     nil)  ;; there are no segs (don't think this can happen)
  181.    (t
  182.     (if (item.daughtern_to (item.relation word 'WordStructure) 'Syllable)
  183.     (item.daughtern_to 
  184.      (item.relation
  185.       (item.daughtern_to (item.relation word 'WordStructure) 'Syllable)
  186.       'SylStructure)
  187.      'Segment)
  188.     (us_find_last_seg (item.relation.prev word 'Word))))))
  189.  
  190. (provide 'pauses)
  191.