分割音声で通話を録音

着信に応答し、次のように設定する方法を示すコード・スニペット。 通話を接続する。通話が完了すると が完了すると eventUrl で指定した record NCCOのアクション のアクションは、ダウンロード用の録画URLを含むウェブフックを受け取ります。

サンプルコードの以下の変数を置き換える:

キー説明
VONAGE_VIRTUAL_NUMBER

Your Vonage Number. E.g. 447700900000

VOICE_TO_NUMBER

The recipient number to call, e.g. 447700900002.

Prerequisites

npm install express body-parser

Write the code

Add the following to record-a-call-with-split-audio.js:

const Express = require('express');
const bodyParser = require('body-parser');

const app = new Express();
app.use(bodyParser.json());

const onInboundCall = (request, response) => {
  const ncco = [
    {
      action: 'record',
      split: 'conversation',
      channels: 2,
      eventUrl: [`${request.protocol}://${request.get('host')}/webhooks/recordings`],
    },
    {
      action: 'connect',
      from: VONAGE_VIRTUAL_NUMBER,
      endpoint: [
        {
          type: 'phone',
          number: VOICE_TO_NUMBER,
        },
      ],
    },
  ];
  response.json(ncco);
};

const onRecording = (request, response) => {
  const recording_url = request.body.recording_url;
  console.log(`Recording URL = ${recording_url}`);

  response.status(204).send();
};

app
  .get('/webhooks/answer', onInboundCall)
  .post('/webhooks/recordings', onRecording);

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

View full source

Run your code

Save this file to your machine and run it:

node record-a-call-with-split-audio.js

試してみる

必要なのは

  1. 通話に応答し、音声を分割して録音する(このコードスニペット)。
  2. 録画をダウンロードするを見る 録音をダウンロードする のコード・スニペットで説明している。