-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtts.php
More file actions
30 lines (22 loc) · 678 Bytes
/
Copy pathtts.php
File metadata and controls
30 lines (22 loc) · 678 Bytes
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
<?php
$SAMPLE_RATE = 44100;
$id = time()."-".rand(1,100000000);
$wav_file = "/tmp/".$id.".wav";
$mp3_file = "/tmp/".$id.".mp3";
$text = escapeshellarg($_REQUEST['txt']);
exec("pico2wave -w ".$wav_file." ".$text);
if(file_exists($wav_file)) {
exec("ffmpeg -i ".$wav_file." -ar ".$SAMPLE_RATE." -y ".$mp3_file);
if(!file_exists($mp3_file)) {
# try avconv instead
exec("avconv -i ".$wav_file." -ar ".$SAMPLE_RATE." -y ".$mp3_file);
}
if(file_exists($mp3_file)) {
$mp3_data = file_get_contents($mp3_file);
unlink($mp3_file);
header("Content-Type: audio/mpeg");
echo $mp3_data;
}
unlink($wav_file);
}
?>