-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrequest_tts.php
29 lines (24 loc) · 1.07 KB
/
request_tts.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
<?php
// Always return JSON from this script
header('Content-Type: application/json');
// Grab all the stuff we need
require_once './vendor/autoload.php';
use ChrisJP\TTS\TTS;
// Instantiate the TTS class
$tts = new TTS();
// If a correctly formed POST request was sent, set the necessary values
if ($tts->isValidPOSTRequest()) {
// Now we know `text` isn't empty. `service` and `voice` can use default values.
if (array_key_exists('service', $_REQUEST)) $tts->setService($_REQUEST['service']);
if (array_key_exists('voice', $_REQUEST)) $tts->setVoice($_REQUEST['voice']);
$tts->setTextToSpeak($_REQUEST['text']);
// Playlist specific
if (array_key_exists('playlist_index', $_REQUEST)) $tts->setPlaylistIndex($_REQUEST['playlist_index']);
if (array_key_exists('voice_name', $_REQUEST)) $tts->setVoiceName($_REQUEST['voice_name']);
}
else {
$tts->exitWithErrorJSON($tts->getLastErrorMessage());
}
// Make a request to the service's API for the audio. This will return JSON containing all the relevant data.
$response = $tts->requestAudio();
exit($response);