SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / plugins / festivalint / sabletowave.scm
blob71293b4c690c5fce2d62aef7dbae29e93f5c2e2e
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-*-mode:scheme-*-
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 ;;;           Author:  Alan W Black
34 ;;;           Date:    November 1997
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; Adapted from text2wave by Alan Black.  Original copyright listed above.
41 ;; Copyright 2004 by Gary Cramblitt <garycramblitt@comcast.net>
43 ;; This scheme module is used by the Festival Interactive plugin,
44 ;; which is part of KTTSD.  To use,
45 ;;    (load sabletowave.scm)
46 ;; after starting Festival interactively, then to synth text containing
47 ;; SABLE tags to a single wave file.
48 ;;    (ktts_sabletowave "sable text" "filename" volume)
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;;; List of generated intermediate wave files.
53 (defvar ktts_wavefiles nil)
55 (define (ktts_save_record_wave utt)
56 "Saves the waveform and records its so it can be joined into a 
57 a single waveform at the end."
58   (let ((fn (make_tmp_filename)))
59     (utt.save.wave utt fn)
60     (set! ktts_wavefiles (cons fn ktts_wavefiles))
61     utt))
63 (define (ktts_combine_waves outfile volume)
64   "Join all the waves together into the desired output file
65 and delete the intermediate ones."
66   (let ((wholeutt (utt.synth (Utterance Text ""))))
67     (mapcar
68      (lambda (d) 
69        (utt.import.wave wholeutt d t)
70        (delete-file d))
71      (reverse ktts_wavefiles))
72 ;;    (if ktts_frequency
73 ;;      (utt.wave.resample wholeutt (parse-number ktts_frequency)))
74     (if (not (equal? volume "1.0"))
75     (begin
76       (utt.wave.rescale wholeutt (parse-number volume))))
77     (utt.save.wave wholeutt outfile 'riff)
78     ))
80 ;;;
81 ;;; Redefine what happens to utterances during text to speech.
82 ;;; Synthesize each utterance and save to a temporary wave file.
83 ;;;
84 (set! tts_hooks (list utt.synth ktts_save_record_wave))
86 (define (ktts_sabletowave text filename volume)
87   (set! ktts_wavefiles nil)
88   ;; Do the synthesis, which creates multiple wave files.
89   (tts_text text 'sable)
90   ;; Now put the waveforms together and adjust volume.
91   (ktts_combine_waves filename volume)