home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / text2wave < prev    next >
Encoding:
Text File  |  2006-12-20  |  6.3 KB  |  178 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:    November 1997
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;;
  38. ;;;  Text to a single waveform like festival_client but without
  39. ;;;  starting hte server
  40. ;;;
  41.  
  42. ;;; Because this is a --script type file I has to explicitly
  43. ;;; load the initfiles: init.scm and user's .festivalrc
  44. (load (path-append datadir "init.scm"))
  45.  
  46. ;;; Process command line arguments
  47. (define (text2wave_help)
  48.   (format t "%s\n"
  49.   "text2wave [options] textfile
  50.   Convert a textfile to a waveform
  51.   Options
  52.   -mode <string>  Explicit tts mode.
  53.   -o ofile        File to save waveform (default is stdout).
  54.   -otype <string> Output waveform type: alaw, ulaw, snd, aiff, riff, nist etc.
  55.                   (default is riff)
  56.   -F <int>        Output frequency.
  57.   -scale <float>  Volume factor
  58.   -eval <string>  File or lisp s-expression to be evaluated before
  59.                   synthesis.
  60. ")
  61.   (quit))
  62.  
  63. ;;; No gc messages
  64. (gc-status nil)
  65.  
  66. ;;; Default argument values
  67. (defvar outfile "-")
  68. (defvar output_type 'riff)
  69. (defvar frequency nil)  ;; default is no frequency modification
  70. (defvar text_files '("-"))
  71. (defvar mode nil)
  72. (defvar volume "1.0")
  73. (defvar wavefiles nil)
  74.  
  75. ;;; Get options
  76. (define (get_options)
  77.  
  78.   (let ((files nil)
  79.     (o argv))
  80.     (if (or (member_string "-h" argv)
  81.         (member_string "-help" argv)
  82.         (member_string "--help" argv)
  83.         (member_string "-?" argv))
  84.     (text2wave_help))
  85.     (while o
  86.       (begin
  87.     (cond
  88.      ((string-equal "-o" (car o))
  89.       (if (not (cdr o))
  90.           (text2wave_error "no output file specified"))
  91.       (set! outfile (car (cdr o)))
  92.       (set! o (cdr o)))
  93.      ((string-equal "-otype" (car o))
  94.       (if (not (cdr o))
  95.           (text2wave_error "no output filetype specified"))
  96.       (set! output_type (car (cdr o)))
  97.       (set! o (cdr o)))
  98.      ((or (string-equal "-f" (car o)) ;; for compatibility and memory loss
  99.           (string-equal "-F" (car o)))
  100.       (if (not (cdr o))
  101.           (text2wave_error "no frequency specified"))
  102.       (set! frequency (car (cdr o)))
  103.       (set! o (cdr o)))
  104.      ((string-equal "-scale" (car o))
  105.       (if (not (cdr o))
  106.           (text2wave_error "no scale specified"))
  107.       (set! volume (car (cdr o)))
  108.       (set! o (cdr o)))
  109.      ((string-equal "-mode" (car o))
  110.       (if (not (cdr o))
  111.           (text2wave_error "no mode specified"))
  112.       (set! mode (car (cdr o)))
  113.       (set! o (cdr o)))
  114.      ((string-equal "-eval" (car o))
  115.       (if (not (cdr o))
  116.           (text2wave_error "no file specified to load"))
  117.       (if (string-matches (car (cdr o)) "^(.*")
  118.           (eval (read-from-string (car (cdr o))))
  119.           (load (car (cdr o))))
  120.       (set! o (cdr o)))
  121.      (t
  122.       (set! files (cons (car o) files))))
  123.     (set! o (cdr o))))
  124.     (if files
  125.     (set! text_files (reverse files)))))
  126.  
  127. (define (text2wave_error message)
  128.   (format stderr "%s: %s\n" "text2wave" message)
  129.   (text2wave_help))
  130.  
  131. (define (save_record_wave utt)
  132. "Saves the waveform and records its so it can be joined into a 
  133. a single waveform at the end."
  134.   (let ((fn (make_tmp_filename)))
  135.     (utt.save.wave utt fn)
  136.     (set! wavefiles (cons fn wavefiles))
  137.     utt))
  138.  
  139. (define (combine_waves)
  140.   "Join all the waves together into the desired output file
  141. and delete the intermediate ones."
  142.   (let ((wholeutt (Utterance Text "")))
  143.     (mapcar
  144.      (lambda (d) 
  145.        (utt.import.wave wholeutt d t)
  146.        (delete-file d))
  147.      (reverse wavefiles))
  148.     (if frequency
  149.     (utt.wave.resample wholeutt (parse-number frequency)))
  150.     (if (not (equal? volume "1.0"))
  151.     (begin
  152.       (utt.wave.rescale wholeutt (parse-number volume))))
  153.     (utt.save.wave wholeutt outfile output_type)
  154.     ))
  155.  
  156. ;;;
  157. ;;; Redefine what happens to utterances during text to speech 
  158. ;;;
  159. (set! tts_hooks (list utt.synth save_record_wave))
  160.  
  161. (define (main)
  162.   (get_options)
  163.  
  164.   ;; do the synthesis
  165.   (mapcar
  166.    (lambda (f) 
  167.      (if mode
  168.      (tts_file f mode)
  169.      (tts_file f (tts_find_text_mode f auto-text-mode-alist))))
  170.    text_files)
  171.  
  172.   ;; Now put the waveforms together at again
  173.   (combine_waves)
  174. )
  175.  
  176. ;;;  Do the work
  177. (main)
  178.