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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;                                                                       ;;
  3. ;;;                Centre for Speech Technology Research                  ;;
  4. ;;;                     University of Edinburgh, UK                       ;;
  5. ;;;                         Copyright (c) 1999                            ;;
  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. ;;;                         Author: Alan W Black
  34. ;;;                         Date:   April 1999
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;;  
  37. ;;;  Support code for phone set definitions
  38. ;;;
  39.  
  40. (defmac (defPhoneSet form)
  41.   (list 'defPhoneSet_real 
  42.     (list 'quote (cadr form))
  43.     (list 'quote (car (cddr form)))
  44.     (list 'quote (cadr (cddr form)))))
  45.  
  46. (define (defPhoneSet_real name featdefs phones)
  47.   "(defPhoneSet NAME FEATTYPES PHONES)
  48. Define a phone set with given name, feature types and
  49. list of phones.  This also selects name as the current phoneset."
  50.   (let (info)
  51.     (if (not (eq? 'Features (car featdefs)))
  52.     (begin
  53.       ;; Old format that has the same number of phone features for
  54.       ;; all phones
  55.       (set! info
  56.         (mapcar 
  57.          (lambda (ph)
  58.            (let ((fvs
  59.               (mapcar
  60.                list
  61.                (mapcar car featdefs)
  62.                (cdr ph))))
  63.            (ps_check_fvals
  64.             (cons (car ph) (cons (list 'type t) fvs))
  65.             (cons t fvs))
  66.            (list (car ph) fvs)))
  67.          phones)))
  68.     ;; else
  69.     ;;   New format where types are specified so phones may have
  70.         ;;   different features
  71.     (set! info
  72.      (mapcar 
  73.       (lambda (ph)
  74.         (let ((fvs 
  75.            (cons 
  76.             (list 'type (cadr ph))
  77.             (mapcar 
  78.              list 
  79.              (mapcar car (cdr (assoc (cadr ph) (cdr featdefs))))
  80.              (cddr ph)))))
  81.           (ps_check_fvals 
  82.            (cons (car ph) fvs)
  83.            (assoc (cadr ph) (cdr featdefs)))
  84.           (list (car ph) fvs)))
  85.       (cdr phones))))
  86.     (Param.set 
  87.      (string-append "phonesets." name)
  88.      info)
  89.     (PhoneSet.select name)
  90.     (list name info)))
  91.  
  92. (define (ps_check_fvals fvs featdefs)
  93.   "(ps_check_fvals fvs featdefs)
  94. Check that feature values in a phone definition are in the defined
  95. set of possibles."
  96.   (mapcar 
  97.    (lambda (fp)
  98.      (let ((def (cdr (assoc (car fp) (cdr featdefs)))))
  99.        (cond
  100.     ((not def)
  101.      (error "Phoneset definition: phone has no defined type" fvs))
  102.     ((not (member_string (car (cdr fp)) def))
  103.      (error 
  104.       (format nil "Phoneset definition: phone feature %l is undefined" fp) fvs)))))
  105.    (cdr (cdr fvs))))
  106.  
  107. (define (PhoneSet.select name)
  108.   "(PhoneSet.select name)
  109. Select named phonset as current."
  110.   (if (feats.present Param (string-append "phonesets." name))
  111.       (Param.set "phoneset" (Param.get (string-append "phonesets." name)))
  112.       (error "no phoneset defined: " name)))
  113.  
  114. (define (PhoneSet.description name)
  115.   "(PhoneSet.description)
  116. Return (lisp) representation of current phoneset."
  117.   (feats.tolisp (Param.get "phoneset")))
  118.  
  119. (define (PhoneSet.list)
  120.   "(PhoneSet.list)
  121. List of the names of the currently defined phonesets."
  122.   ;; This isn't a particularly efficient way to get the answer
  123.   (mapcar car (feats.tolisp (Param.get "phonesets"))))
  124.  
  125. (define (PhoneSet.silences sils)
  126.   "(PhoneSet.silences SILLIST)
  127. Define the silence phones for the currently selected phoneset."
  128.   (Param.set "phoneset.silences" sils))
  129.  
  130. (provide 'phoneset)
  131.  
  132.  
  133.  
  134.  
  135.