Twilio有一个非常古老的博客条目,涉及在浏览器中测试TTS:
https://www.twilio.com/blog/2011/08/testing-twilios-text-to-speech-engine-using-twilio-client.html
不幸的是,它没有足够的信息来进行测试。它还包含许多无效链接,并提到了我找不到的Github项目。
我真的希望用户能够在取消表单并开始拨打电话之前听到他们的公告听起来会是什么。
我使用Lasso(可触发向Twilio REST API的CURL请求),但是任何形式的教程或提示都将不胜感激。
答案 0 :(得分:0)
如果您在Twilio上设置了一个模拟帐户并使用Glitch在线php测试器(https://glitch.com/edit/#!/php-poc)或本地环境,则可以像我一样创建一个可行的示例。您需要填写空字符串以与您的应用名称相对应。在网站中搜索TwiML,以转到右侧部分,以设置服务器的正确URL,TWilio将根据请求读取内容(xml)。在我的情况下,URL已在Glitch上经过http://<server>/?incoming-call.php
测试。
您需要获取Twilio PHP SDK,并将https://github.com/twilio/starter-php中的Services/Twilio/Capability.php
包含在服务器代码中。
<?php
require __DIR__ . '/../vendor/autoload.php';
$url = [];
$url = explode('?', $_SERVER['REQUEST_URI']);
if (count($url) == 2 && $url[1] == 'incoming-call.php')
{
header('Content-type: text/xml');
$response = new Twilio\Twiml;
$dialogue = trim($_REQUEST['dialogue']);
$voice = (int) $_REQUEST['voice'];
if (strlen($dialogue) == 0)
{
$dialogue = 'Please enter some text to be spoken.';
}
if ($voice == 1)
{
$gender = 'man';
}
else
{
$gender = 'woman';
}
$response->say($dialogue);
echo $response;
exit;
}
require_once('Services/Twilio/Capability.php');
$accountsid = ''; // YOUR TWILIO ACCOUNT SID
$authtoken = ''; // YOUR TWILIO AUTH TOKEN
$fromNumber = ''; // PHONE NUMBER CALLS WILL COME FROM
$APP_SID = '';
$token = new Services_Twilio_Capability($accountsid, $authtoken);
$token->allowClientOutgoing($APP_SID);
?>
<html>
<head>
<title>Text-To-Speech</title>
<script type="text/javascript" src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.5/twilio.js"></script>
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token->generateToken();?>",{"debug":true});
$(document).ready(function() {
$("#submit").click(function() {
speak();
});
});
function speak() {
var dialogue = $("#dialogue").val();
var voice =
$('input:radio[name=voice]:checked').val();
Twilio.Device.connect({ 'dialogue' :
dialogue, 'voice' : voice });
}
</script>
</head>
<body>
<p>
<label for="dialogue">Text to be spoken</label>
<input type="text" id="dialogue" name="dialogue"
size="50">
</p>
<p>
<label for="voice-male">Male Voice</label>
<input type="radio" id="voice-male" name="voice"
value="1" checked="checked">
<label for="voice-female">Female Voice</label>
<input type="radio" id="voice-female" name="voice"
value="2">
</p>
<p>
<input type="button" id="submit" name="submit"
value="Speak to me">
</p>
</body>
</html>