是否可以使用nexmo/vonage和PHP或Javascript通过web浏览器进行实时语音通话?我使用的是名为nexmo/laravel的库。下面是我使用的示例代码:
$nexmo = Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => '855969818674'
]],
'from' => [
'type' => 'phone',
'number' => '63282711511'
],
'answer_url' => ['https://gist.githubusercontent.com/jazz7381/d245a8f54ed318ac2cb68152929ec118/raw/6a63a20d7b1b288a84830800ab1813ebb7bac70c/ncco.json'],
'event_url' => [backpack_url('call/event')]
]);有了这些代码,我可以发送文本到语音,但我如何才能进行实时语音对话?
发布于 2020-06-30 18:03:24
从上面共享的代码可以看出,您可能还没有实例化Nexmo PHP SDK的客户端实例,这是实例化所必需的。您使用实例化并经过身份验证的客户端进行出站呼叫。
例如,首先使用以下内容实例化一个客户端,提供私钥文件的文件路径、应用程序ID、API密钥和API密钥。您可以从Dashboard获取所有这些内容
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents((NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));然后,一旦您有了一个有凭据的客户端,您就可以在其上调用$client->calls()方法。例如:
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'answer_url' => ['https://example.com/answer'],
'event_url' => ['https://example.com/event'],
]);您可以在GitHub上找到有关使用PHP SDK的更多信息。您还可以在我们的developer portal上找到代码片段、教程和更多说明。
https://stackoverflow.com/questions/62653133
复制相似问题