home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / lib / mbrola.scm < prev    next >
Lisp/Scheme  |  1999-05-30  |  5KB  |  103 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. ;;;  Support for MBROLA as an external module.
  35. ;;;
  36.  
  37. ;;; You might want to set this in your sitevars.scm
  38. (defvar mbrola_progname "/cstr/external/mbrola/mbrola"
  39.   "mbrola_progname
  40.   The program name for mbrola.")
  41. (defvar mbrola_database "fr1"
  42.   "mbrola_database
  43.  The name of the MBROLA database to usde during MBROLA Synthesis.")
  44.  
  45. (define (MBROLA_Synth utt)
  46.   "(MBROLA_Synth UTT)
  47.   Synthesize using MBROLA as external module.  Basically dump the info
  48.   from this utterance. Call MBROLA and reload the waveform into utt.
  49.   [see MBROLA]"
  50.   (let ((filename (make_tmp_filename)))
  51.     (save_segments_mbrola utt filename)
  52.     (system (string-append mbrola_progname " " 
  53.                mbrola_database " "
  54.                filename " "
  55.                filename ".au"))
  56.     (utt.import.wave utt (string-append filename ".au"))
  57.     (apply_hooks after_synth_hooks utt)
  58.     (delete-file filename)
  59.     (delete-file (string-append filename ".au"))
  60.     utt))
  61.  
  62. (define (save_segments_mbrola utt filename)
  63.   "(save_segments_mbrola UTT FILENAME)
  64.   Save segment information in MBROLA format in filename.  The format is
  65.   phone duration (ms) [% position F0 target]*. [see MBROLA]"
  66.   (let ((fd (fopen filename "w")))
  67.     (mapcar
  68.      (lambda (segment) 
  69.        (save_seg_mbrola_entry 
  70.     (item.feat segment 'name)
  71.     (item.feat segment 'segment_start)
  72.     (item.feat segment 'segment_duration)
  73.     (mapcar
  74.      (lambda (targ_item)
  75.        (list
  76.         (item.feat targ_item "pos")
  77.         (item.feat targ_item "f0")))
  78.      (item.relation.daughters segment 'Target)) ;; list of targets
  79.     fd))
  80.      (utt.relation.items utt 'Segment))
  81.     (fclose fd)))
  82.  
  83. (define (save_seg_mbrola_entry name start dur targs fd)
  84.   "(save_seg_mbrola_entry ENTRY NAME START DUR TARGS FD)
  85.   Entry contains, (name duration num_targs start 1st_targ_pos 1st_targ_val)."
  86.   (format fd "%s %d " name (nint (* dur 1000)))
  87.   (if targs     ;; if there are any targets
  88.       (mapcar
  89.        (lambda (targ) ;; targ_pos and targ_val
  90.      (let ((targ_pos (car targ))
  91.            (targ_val (car (cdr targ))))
  92.                                       
  93.        (format fd "%d %d " 
  94.            (nint (* 100 (/ (- targ_pos start) dur))) ;; % pos of target
  95.            (nint (parse-number targ_val)))           ;; target value
  96.        ))
  97.        targs))
  98.   (terpri fd)
  99.   (terpri fd)
  100. )
  101.     
  102. (provide 'mbrola)
  103.