home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / festival / examples / text2pos < prev    next >
Encoding:
Text File  |  2006-05-21  |  3.8 KB  |  83 lines

  1. #!/usr/bin/festival --script
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-*-mode:scheme-*-
  3. ;;                                                                       ;;
  4. ;;                Centre for Speech Technology Research                  ;;
  5. ;;                     University of Edinburgh, UK                       ;;
  6. ;;                       Copyright (c) 1996,1997                         ;;
  7. ;;                        All Rights Reserved.                           ;;
  8. ;;                                                                       ;;
  9. ;;  Permission is hereby granted, free of charge, to use and distribute  ;;
  10. ;;  this software and its documentation without restriction, including   ;;
  11. ;;  without limitation the rights to use, copy, modify, merge, publish,  ;;
  12. ;;  distribute, sublicense, and/or sell copies of this work, and to      ;;
  13. ;;  permit persons to whom this work is furnished to do so, subject to   ;;
  14. ;;  the following conditions:                                            ;;
  15. ;;   1. The code must retain the above copyright notice, this list of    ;;
  16. ;;      conditions and the following disclaimer.                         ;;
  17. ;;   2. Any modifications must be clearly marked as such.                ;;
  18. ;;   3. Original authors' names are not deleted.                         ;;
  19. ;;   4. The authors' names are not used to endorse or promote products   ;;
  20. ;;      derived from this software without specific prior written        ;;
  21. ;;      permission.                                                      ;;
  22. ;;                                                                       ;;
  23. ;;  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        ;;
  24. ;;  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ;;
  25. ;;  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ;;
  26. ;;  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     ;;
  27. ;;  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ;;
  28. ;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ;;
  29. ;;  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ;;
  30. ;;  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ;;
  31. ;;  THIS SOFTWARE.                                                       ;;
  32. ;;                                                                       ;;
  33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  34. ;;;           Author:  Alan W Black
  35. ;;;           Date:    August 1996
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;;
  38. ;;;  Reads in text from stdin and outputs text/pos on stdout
  39. ;;;
  40. ;;;  Designed to show how simple filters can be written in Festival
  41. ;;;
  42. ;;;  First we defined a function that processes an utterance enough
  43. ;;;  to predict part of speech, namely, tokenize it, find the words
  44. ;;;  and then run the POS tagger on it.
  45. ;;;  Then we define a function to extract the word and pos tag itself
  46. ;;;
  47. ;;;  We redefine the basic functions run on utterances during text to
  48. ;;;  speech to be our two newly-defined function and then simply
  49. ;;;  run tts on standard input.
  50. ;;;
  51.  
  52. ;;; Because this is a --script type file I has to explicitly
  53. ;;; load the initfiles: init.scm and user's .festivalrc
  54. (load (path-append datadir "init.scm"))
  55.  
  56. (define (find-pos utt)
  57. "Main function for processing TTS utterances.  Predicts POS and
  58. prints words with their POS"
  59.   (Token utt)
  60.   (POS utt)
  61. )
  62.  
  63. (define (output-pos utt)
  64. "Output the word/pos for each word in utt"
  65.  (mapcar
  66.   (lambda (pair)
  67.     (format t "%l/%l\n" (car pair) (car (cdr pair))))
  68.   (utt.features utt 'Word '(name pos))))
  69.  
  70. ;;;
  71. ;;; Redefine what happens to utterances during text to speech 
  72. ;;;
  73. (set! tts_hooks (list find-pos output-pos))
  74.  
  75. ;;; Stop those GC messages
  76. (gc-status nil)
  77.  
  78. ;;; Do the work
  79. (tts_file "-")
  80.  
  81.  
  82.  
  83.