-
Notifications
You must be signed in to change notification settings - Fork 2
/
ajax_loquendo.php
70 lines (54 loc) · 1.92 KB
/
ajax_loquendo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the ISA package.
*
* (c) Informatici Senza Frontiere Onlus <http://informaticisenzafrontiere.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include 'config.php';
include 'functions.php';
$tmpdir = "./tmp";
$available_voices = array();
$available_voices['it'] = array();
$available_voices['en'] = array();
// ITALIAN
$available_voices['it'][1] = 'Fabio';
$available_voices['it'][2] = 'Giulia';
$available_voices['it'][0] = 'Marcello';
//ENGLISH
$available_voices['en'][0] = '';
if (isset($_POST["language"]) && ($_POST["language"] != '')) {
$chosen_voice = $available_voices[$_POST["language"]][0];
} else $chosen_voice = $available_voices['it'][0];
if (isset($_POST["speech"]) && ($_POST["speech"] != '')) {
$speech = stripslashes(trim($_POST["speech"]));
$speech = substr($speech, 0, 2048);
$volume_scale = intval($_POST["volume_scale"]);
if ($volume_scale <= 0) { $volume_scale = 1; }
if ($volume_scale > 100) { $volume_scale = 100; }
// continue only if some text was entered for conversion
if ($speech != "") {
// unique file name
$filename = substr($speech,0,32);
$filename = strtolower(trim($filename));
$filename = preg_replace("/[^a-zA-Z0-9]/", "", $filename);
// other file names
$speech_file = "{$tmpdir}/{$filename}";
// open the temp file for writing
$fh = fopen($speech_file, "w+");
if ($fh) {
fwrite($fh, $speech);
fclose($fh);
}
// if the speech file exists, use text2wave
if (file_exists($speech_file)) {
$tts_cmd = sprintf($tts_bin_path . " -q -b -v".$chosen_voice." %s",$speech_file);
trace("cmd: ".$tts_cmd);
exec($tts_cmd);
// delete the temp speech file
unlink($speech_file);
}
}
}