Last active
August 14, 2024 09:25
-
-
Save t2-support-gists/5189883 to your computer and use it in GitHub Desktop.
Text To Speech PHP RESTFul App 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AT&T API Platform Samples - TextToSpeech app 1 | |
------------------------------ | |
This file describes how to set-up, configure and run the PHP Applications | |
using AT&T API Platform services. | |
It covers all steps required to register the application and, | |
based on the generated API keys and secrets, create and run one's own | |
full-fledged sample applications. | |
1. Configuration | |
2. Installation | |
3. Parameters | |
1. Configuration | |
Configuration consists of a few steps necessary to get an application | |
registered with the proper services and | |
endpoints, depending on the type of client-side application | |
(autonomous/non-autonomous). | |
To register an application, go to https://developer.att.com/developer/mvc/auth/login and login | |
with your valid username and password. | |
Next, choose "My Apps" from the bar at the top of the page and click the | |
"Setup a New Application" button. | |
Fill in the form, in particular all fields marked as "required". | |
Having your application registered, you will get back an important pair of | |
data: an API key and Secret key. They are | |
necessary to get your applications working with the AT&T API Platform. See | |
'Adjusting parameters' below to learn how to use | |
these keys. | |
Initially your newly registered application is restricted to the "Sandbox" | |
environment only. To move it to production, | |
you may promote it by clicking the "Promote to production" button. Notice | |
that you will get a different API key and secret, | |
so these values in your application should be adjusted accordingly. | |
Depending on the kind of authentication used, an application may be based on | |
either the Autonomous Client or the Web-Server | |
Client OAuth flow (see https://developer.att.com/apis/oauth-2/docs). | |
2. Installation | |
** Requirements | |
Apache web server | |
PHP 5.4+ | |
Apache and PHP configured, on most GNU/Linux systems if installed using packages | |
this will be done automatically. | |
Copy the sample application folder to Apache web root folder, for example | |
/var/www/html. | |
3. Parameters | |
Each application contains a config.php file. This file holds configurable parameters described in an | |
easy-to-read format. Please modify the config.php file using the comments specified within the file. | |
Note: If your application is promoted from Sandbox environment to Production environment and you decide to use | |
production application settings, you must update parameters as per production application details. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$api_key = "4bf126e402d74a1e922a8c8bf256b2ac"; | |
$secret_key = "5b5e0d7003967dc6"; | |
$FQDN = "https://api.att.com"; | |
$scope = "TTS"; | |
$oauth_file = "speechoauthtoken.php"; | |
$speech_context_config = array('Generic', 'TV', 'BusinessSearch', 'Websearch', | |
'SMS', 'Voicemail', 'QuestionAndAnswer', 'Gaming', 'SocialMedia'); | |
$default_file = "default.wav"; | |
$x_arg = "AppId=12345,OrgId=54321,VoiceName=mike"; | |
$xSpeechSubContext = 'Chat'; | |
$audioFolder = "audio"; | |
$linkSource = 'https://gist.github.com/5189883'; | |
$linkDownload = 'https://github.com/attdevsupport/ATT_APIPlatform_SampleApps/tree/master/RESTFul/TextToSpeech/PHP/app1'; | |
$linkHelp = 'https://raw.github.com/attdevsupport/ATT_APIPlatform_SampleApps/master/RESTFul/TextToSpeech/PHP/app1/README.txt'; | |
$endpoint = $FQDN . "/speech/v3/textToSpeech"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
require __DIR__ . '/config.php'; | |
require_once __DIR__ . '/src/Controller/SpeechController.php'; | |
require_once __DIR__ . '/lib/Util/Util.php'; | |
use Att\Api\Util\Util; | |
$controller = new SpeechController(); | |
$controller->handleRequest(); | |
$results = $controller->getResults(); | |
$errors = $controller->getErrors(); | |
?> | |
<!DOCTYPE html> | |
<!-- | |
Copyright 2014 AT&T | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<!--[if lt IE 7]> <html class="ie6" lang="en"> <![endif]--> | |
<!--[if IE 7]> <html class="ie7" lang="en"> <![endif]--> | |
<!--[if IE 8]> <html class="ie8" lang="en"> <![endif]--> | |
<!--[if gt IE 8]><!--> | |
<html lang="en"> | |
<!--<![endif]--> | |
<head> | |
<title>AT&T Sample Speech Application - Text To Speech</title> | |
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> | |
<meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1"> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<link rel="stylesheet" type="text/css" href="style/common.css"> | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-33466541-1']); | |
_gaq.push(['_trackPageview']); | |
(function () { | |
var ga = document.createElement('script'); | |
ga.type = 'text/javascript'; | |
ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' | |
: 'http://www') | |
+ '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(ga, s); | |
})(); | |
</script> | |
</head> | |
<body> | |
<div id="pageContainer" class="pageContainer"> | |
<div id="header"> | |
<div class="logo" id="top"></div> | |
<div id="menuButton" class="hide"> | |
<a id="jump" href="#nav">Main Navigation</a> | |
</div> | |
<ul class="links" id="nav"> | |
<li> | |
<a href="<?php echo $linkSource; ?>" | |
target="_blank">Source<img src="images/source.png" alt="Source" /></a> | |
<span class="divider"> | </span> | |
</li> | |
<li> | |
<a href="<?php echo $linkDownload; ?>" | |
target="_blank">Download<img src="images/download.png" alt="Link"></a> | |
<span class="divider">| </span> | |
</li> | |
<li><a href="<?php echo $linkHelp; ?>" target="_blank">Help</a></li> | |
<li id="back"><a href="#top">Back to top</a></li> | |
</ul> <!-- end of links --> | |
</div> <!-- end of header --> | |
<div class="content"> | |
<div class="contentHeading"> | |
<h1>AT&T Sample Application - Text To Speech</h1> | |
<div id="introtext"> | |
<div><b>Server Time: </b><?php echo Util::getServerTime(); ?></div> | |
<div> | |
<b>Client Time: </b> | |
<script> | |
document.write("" + new Date()); | |
</script> | |
</div> | |
<div> | |
<b>User Agent: </b> | |
<script> | |
document.write("" + navigator.userAgent); | |
</script> | |
</div> | |
</div> <!-- end of introtext --> | |
</div><!-- end of contentHeading --> | |
</div> <!-- end of content --> | |
<div class="formBox" id="formBox"> | |
<div id="formContainer" class="formContainer"> | |
<div id="formData"> | |
<form name="TextToSpeech" action="index.php" method="post"> | |
<h3>Content Type:</h3> | |
<select name="ContentType" id="ContentType"> | |
<option value="text/plain" selected="selected">text/plain</option> | |
<option value="application/ssml+xml">application/ssml+xml</option> | |
</select> | |
<h3>Content:</h3> | |
<label>text/plain</label><br> | |
<textarea id="plaintext" name="plaintext" readonly="readonly" | |
rows="4"><?php echo htmlspecialchars(file_get_contents(__DIR__ . '/text/PlainText.txt')); ?></textarea><br> | |
<label>application/ssml</label><br> | |
<textarea id="ssml" name="ssml" readonly="readonly" | |
rows="4"><?php echo htmlspecialchars(file_get_contents(__DIR__ . '/text/SSMLWithPhoneme.txt')); ?></textarea> | |
<h3>X-Arg:</h3> | |
<textarea id="x_arg" type="text" name="x_arg" readonly="readonly" rows="4" | |
value="<?php echo $x_arg; ?>"><?php echo $x_arg; ?></textarea> | |
<button id="btnSubmit" name="TextToSpeechButton" type="submit"> | |
Submit | |
</button> | |
</form> | |
<?php | |
if (isset($results[SpeechController::RESULT_TTS])) { | |
$response = $results[SpeechController::RESULT_TTS]; | |
?> | |
<div class="successWide" align="left"> | |
<strong>SUCCESS:</strong> | |
<br> | |
<audio controls="controls" autobuffer="autobuffer" autoplay="autoplay"> | |
<source src="data:audio/wav;base64,<?php echo base64_encode($response); ?>" /> | |
</audio> | |
</div> | |
<?php } ?> | |
<?php | |
if (isset($errors[SpeechController::ERROR_TTS])) { | |
$error = $errors[SpeechController::ERROR_TTS]; | |
?> | |
<div class="errorWide"> | |
<strong>ERROR:</strong> | |
<br> | |
<?php echo htmlspecialchars($error); ?> | |
</div> | |
<?php } ?> | |
</div><!-- end formData --> | |
</div><!-- end formContainer --> | |
</div><!-- end formBox --> | |
<div id="footer"> | |
<div id="ft"> | |
<div id="powered_by">Powered by AT&T Cloud Architecture</div> | |
<p> | |
The Application hosted on this site are working examples intended to be used for reference in creating | |
products to consume AT&T Services and not meant to be used as part of your product. The data in | |
these pages is for test purposes only and intended only for use as a reference in how the services | |
perform. | |
<br> <br> | |
To access your apps, please go to | |
<a href="https://developer.att.com/developer/mvc/auth/login" | |
target="_blank">https://developer.att.com/developer/mvc/auth/login</a> | |
<br> For support refer to | |
<a href="https://developer.att.com/support">https://developer.att.com/support</a> | |
<br> <br> | |
© 2014 AT&T Intellectual Property. All rights reserved. | |
<a href="http://developer.att.com/" target="_blank">http://developer.att.com</a> | |
</p> | |
</div> <!-- end of ft --> | |
</div> <!-- end of footer --> | |
</div> <!-- end of page_container --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* | |
293ec4cbf742e9e3dd2a25ff77114bc | |
0 | |
6279e38cc8afd6b3d64d1012fea584ad9bad0110 | |
*/ ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I noticed that you made a sms api, could direct me to a supplier of SMS shortcode?