changed git call from https to git readonly
[atutor.git] / mods / atalker / admin_voice.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2005 by Greg Gay                                  */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id: index.php 5123 2005-07-12 14:59:03Z greg $
14
15         // Get the time to use as a default filename
16         $now = time();
17         $scheme_out = AT_SPEECH_DIR.$now.'.scm';
18         //$sable_in= AT_SPEECH_DIR.$now.'.sable';
19         // Build the Scheme file. Lots more can be done here to customize voices
20         
21 if($_POST['type'] != "sable"){
22         $scheme_in .= "(";
23         $scheme_in .= $_POST['voice'];
24         $scheme_in .= ")\n";
25         $scheme_in .= "(";
26         $scheme_in .= "Parameter.set 'Duration_Stretch ".$_POST['duration'];
27         $scheme_in .= ")";
28
29         // create a scheme file with the voice properties
30         $fp = fopen($scheme_out,'w');
31         if (!$fp) {
32                 echo _AT(AT_ERROR_TTS__NOT_CREATE_SCHEME);
33                 exit;
34         }
35         fputs($fp, $scheme_in);
36         fclose($fp);
37 }
38
39 if($_POST['create'] && !$_GET['page']){
40         $d = "0";
41         if($_POST['file_type'] == "mp3"){
42                 if(shell_exec('lame --longhelp')){
43                         $command2 = 'lame --quiet '.$file_out.' '. $file_out_mp3;
44                 }else if (shell_exec('bladeenc -h')) {
45                         $command2 = 'bladeenc -quiet '.$file_out.' '. $file_out_mp3;    
46                 }else{
47                         $error = "TTS_MP3_ENCODER";
48                         $msg->addError($error);
49                 }
50         }
51         if($_POST['file_type'] == "ogg"){
52         
53                 $command = 'oggenc --version';
54                 $command = escapeshellcmd($command);
55                 
56                 if(shell_exec($command) == ''){
57                         $error = "TTS_OGG_ENCODER";
58                         $msg->addError($error);
59                 }else{
60                         $command2 = 'oggenc -quiet '.$file_out.' '. $file_out_ogg;      
61                 }
62         }
63         if(!$error){
64         
65                 foreach ($_POST['check'] as $lang_var){
66                         
67                         $file_recieve = AT_SPEECH_URL.$lang_var.'.'.$_POST['file_type'];
68                         $voice_file = AT_SPEECH_TEMPLATE_DIR.$lang_var.'.'.$_POST['file_type'];
69                         
70                         $sql = "SELECT * from ".TABLE_PREFIX."language_text WHERE language_code = '".$_SESSION['lang']."' AND term = '".$lang_var."'";
71                         $result = mysql_query($sql, $db);
72                         $row = mysql_fetch_row($result);
73
74                         if($_POST['file_type'] == "mp3"){
75                                 //$file_in =  AT_SPEECH_DIR.$lang_var.'.sable';
76                                 $file_out = AT_SPEECH_DIR.$lang_var.'.wav';
77                                 //If SABLE is being used, generate the SBALE markup as the input file
78                                 if($_POST['type'] == "sable"){
79                                         $file_in =  AT_SPEECH_DIR.$lang_var.'.sable';                           
80                                         $sable_out = '<?xml version="1.0"?>
81                                         <!DOCTYPE SABLE PUBLIC "-//SABLE//DTD SABLE speech mark up//EN" "Sable.v0_2.dtd"[]>
82                                         <SABLE>
83                                         <LANGUAGE ID="'.$_POST['language'].'" CODE="ISO-8859-1">
84                                         <SPEAKER NAME="'.$_POST['speaker'].'">
85                                         <PITCH BASE="'.$_POST['base'].'" MIDDLE="'.$_POST['middle'].'" RANGE="'.$_POST['range'].'">
86                                         <RATE SPEED="'.$_POST['rate'].'">
87                                         <VOLUMN LEVEL="'.$_POST['volumn'].'">';
88                                                 $sable_out .= $row[3].".";
89                                                 $sable_out .= '
90                                         </VOLUMN>
91                                         </RATE>
92                                         </PITCH>
93                                         </SPEAKER>
94                                         </LANGUAGE>
95                                         </SABLE>';
96                                         //write the SABLE file
97                                         $fp = fopen($file_in,'w');
98                                         if (!$fp) {
99                                                 echo _AT(AT_ERROR_TTS__NOT_CREATE_SABLE);
100                                                 exit;
101                                         }
102                                         fputs($fp, $sable_out);
103                                         fclose($fp);
104                                         $command = "text2wave $file_in -o $file_out -F 48000";
105                                 }else{
106                                         // If not SABLE being used, generate a standard scheme file and input text file.
107                                         $file_in =  AT_SPEECH_DIR.$lang_var.'.txt';
108                                         $scheme_out = AT_SPEECH_DIR.$now.'.scm';        
109                                         $file_props = "-mode --tts -eval ".AT_SPEECH_DIR.$now.".scm";
110                                         $fp = fopen($file_in,'w');
111                                         if (!$fp) {
112                                                 echo _AT(AT_ERROR_TTS__NOT_CREATE_TEXT);echo 'Unable to create '.$name.' Text file.';
113                                                 exit;
114                                         }
115                                         fputs($fp, $row[3].'.');
116                                         fclose($fp);    
117                                         $command = "text2wave $file_props $file_in -o $file_out -F 48000  -scale ".$_POST['volumn']."";
118                                 }
119
120
121                                 $file_out_mp3 = AT_SPEECH_DIR.$lang_var.'.mp3';
122
123                                 if(shell_exec('lame --longhelp')){
124                                         $command2 = 'lame --quiet '.$file_out.' '. $file_out_mp3;
125                                 }else if (shell_exec('bladeenc -h')) {
126                                         $command2 = 'bladeenc -quiet '.$file_out.' '. $file_out_mp3;    
127                                 }
128                                 escapeshellcmd($command);
129                                 escapeshellcmd($command2);
130                                 passthru($command);
131                                 passthru($command2);
132                                 
133                                 if(!copy($file_recieve, $voice_file)){
134                                         $error =  TTS_FILE_SAVE_FAILED;
135                                         $msg->addError($error);
136                                 }
137                                 
138                                 //gen_tts();
139                         
140                         }else if($_POST['file_type'] == "ogg"){ 
141                                 $file_out = AT_SPEECH_DIR.$lang_var.'.wav';
142                         
143                                 if($_POST['type'] == "sable"){
144                                         $file_in =  AT_SPEECH_DIR.$lang_var.'.sable';                           
145                         
146                                         $sable_out = '<?xml version="1.0"?>
147                                         <!DOCTYPE SABLE PUBLIC "-//SABLE//DTD SABLE speech mark up//EN" "Sable.v0_2.dtd"[]>
148                                         <SABLE>
149                                         <LANGUAGE ID="'.$_POST['language'].'" CODE="ISO-8859-1">
150                                         <SPEAKER NAME="'.$_POST['speaker'].'">
151                                         <PITCH BASE="'.$_POST['base'].'" MIDDLE="'.$_POST['middle'].'" RANGE="'.$_POST['range'].'">
152                                         <RATE SPEED="'.$_POST['rate'].'">
153                                         <VOLUMN LEVEL="'.$_POST['volumn'].'">';
154                                                 $sable_out .= $row[3].".";
155                                                 $sable_out .= '
156                                         </VOLUMN>
157                                         </RATE>
158                                         </PITCH>
159                                         </SPEAKER>
160                                         </LANGUAGE>
161                                         </SABLE>';
162                                         //write the SABLE file
163                                         $fp = fopen($file_in,'w');
164                                         if (!$fp) {
165                                                 echo _AT(AT_ERROR_TTS__NOT_CREATE_SABLE);
166                                                 exit;
167                                         }
168                                         
169                                         fputs($fp, $sable_out);
170                                         fclose($fp);
171                                         $command = "text2wave $file_in -o $file_out -F 48000";
172
173                                 } 
174                                 
175                                 $file_props = "-mode --tts -eval ".AT_SPEECH_DIR.$now.".scm";
176                                 $file_out_ogg = AT_SPEECH_DIR.$lang_var.'.ogg';
177                                 $command2 = 'oggenc -quiet '.$file_out.' '. $file_out_ogg;
178                                 
179                                 escapeshellcmd($command);
180                                 escapeshellcmd($command2);
181                                 passthru($command);
182                                 passthru($command2);
183                                 
184                                 if(!copy($file_recieve, $voice_file)){
185                                         $error =  TTS_FILE_SAVE_FAILED;
186                                         $msg->addError($error);
187                                 }
188                                 
189                                 //gen_tts();
190                                 
191                         }else if($_POST['file_type'] == "wav"){
192                                 $error =  TTS_NO_WAV_ALLOWED;
193                                 $msg->addError($error); 
194                         }
195                 }
196                 
197                 $feedback =  array(TTS_VOICE_SAVED);
198                 $msg->addFeedback($feedback);           
199         }
200
201 }else if($_POST['remove'] && !$_GET['page']){
202
203                 if(!$_POST['check']){
204                         $error =  array(TTS_FILES_REMOVED_CHECK);
205                         $msg->addError($error);
206                 }else{
207                 
208                         foreach ($_POST['check'] as $lang_var){
209                                 if(file_exists(AT_SPEECH_TEMPLATE_DIR.$lang_var.".ogg")){
210                                 
211                                         unlink(AT_SPEECH_TEMPLATE_DIR.$lang_var.".ogg");        
212                                         
213                                 }else if(file_exists(AT_SPEECH_TEMPLATE_DIR.$lang_var.".mp3")){
214                                 
215                                         unlink(AT_SPEECH_TEMPLATE_DIR.$lang_var.".mp3");
216                                         
217                                 };
218                                 
219                         }
220                         $feedback =  array(TTS_FILES_REMOVED);
221                         $msg->addFeedback($feedback);
222                         
223                 }
224
225 }
226 ?>