我使用Nexmo composer包在我的应用程序中进行文本到语音转换。SMS运行良好,但T2S服务存在问题。当我发送请求时,它会呼叫我,但当我单击"应答"时,它将结束呼叫。以下是添加到T2S调用中的json示例:
[ "{ "action": "talk",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut ligula nec quam pulvinar rn bibendum. Sed nisi ipsum, pretium tempor bibendum vel, condimentum ut erat. Vivamus sagittis, rn mi eget tincidunt laoreet, diam ligula euismod nisi, sit amet maximus ipsum arcu facilisis erat. rn Donec sed efficitur enim. Phasellus sagittis pulvinar semper. Pellentesque quis nibh sed neque rn maximus sodales. Morbi vel ornare elit. ",
"voiceName": "Salli" }" ]
我也试试这个:
{ "action": "talk",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut ligula nec quam pulvinar rn bibendum. Sed nisi ipsum, pretium tempor bibendum vel, condimentum ut erat. Vivamus sagittis, rn mi eget tincidunt laoreet, diam ligula euismod nisi, sit amet maximus ipsum arcu facilisis erat. rn Donec sed efficitur enim. Phasellus sagittis pulvinar semper. Pellentesque quis nibh sed neque rn maximus sodales. Morbi vel ornare elit. ",
"voiceName": "Salli" }
但都不起作用。
下面是一个例子,发送呼叫给我,并将文件制作到S3中,Nexmo将读取:
$json_file = str_random(16).'.json';
$data = [
'action' => 'talk',
'text' => $event->notification->content.' '.$event->arrived_in,
'voiceName' => 'Salli'
];
$newJsonString = json_encode($data, JSON_PRETTY_PRINT);
$this->flysystem->connection('awss3');
$this->flysystem->write('call_cleanup_notifications/'.$json_file, stripslashes($newJsonString));
$basic = new Basic(getenv('NEXMO_KEY'), getenv('NEXMO_SECRET'));
$this->flysystem->connection('awss3');
$key = $this->flysystem->read('application.key');
$keypair = new Keypair($key, getenv('NEXMO_APPLICATION_ID'));
$client = new Client(new Container($basic, $keypair));
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => $event->cleanupUserChanel->home_phone_number
]],
'from' => [
'type' => 'phone',
'number' => getenv('NEXMO_SMS_FROM')
],
'answer_url' => [getenv('GATEWAY_API_URL').'/notification_call/'.$json_file],
]);
我认为您已经非常接近第一个例子了,但NCCO不是非常有效的JSON。在开始时,在[
之后,在对象从{
开始之前删除引号"
。(然后在最后也这样做,删除]
之前的最后一个引号。希望这有帮助!
以下是使此json T2S文件具有有效格式的解决方案:
$json_file = str_random(16) . '.json';
$data[] = (object) [
'action' => 'talk',
'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
'voiceName' => 'Salli'
];
//save file in file system using flysystem composer package
$this->flysystem->write($json_file, json_encode($data,JSON_PRETTY_PRINT));