【发布时间】:2021-07-01 01:22:48
【问题描述】:
我需要在 php 中创建一个 IVR 应用程序,系统会在其中启动出站呼叫并捕获来自用户的语音响应。
我该怎么做呢?
这是我的代码(不捕获用户的响应)
voice.xml 内容
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/complex_gather.xml -->
<Response>
</Response>
completed.php 内容
file_put_contents('voice.txt',$_SERVER['QUERY_STRING']);
主代码
<?php
require_once 'vendor/autoload.php';
use Twilio\Rest\Client;
use Twilio\TwiML\VoiceResponse;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = "xxx";
$token = "xxx";
$twilio = new Client($sid, $token);
$call = $twilio->calls
->create("+1310XXXXXXX", // to
"+15676777774", // from
[
"method" => "GET",
"statusCallbackMethod" => "POST",
"url" => "http://xxxx.com/voice.xml"
]
);
$response = new VoiceResponse();
$gather = $response->gather(['action' => '/completed.php','method' => 'GET', 'input'=>'speech','timeout'=>3,''=>'true','speech_model'=>'phone']);
$gather->say('Enter something, or not');
echo $response;
【问题讨论】: