Download a recording

In this building block you see how to download a recording.

Example

Replace the following variables in the example code:

Key Description
RECORDING_URL The URL of the recording to download. You typically get this from the JSON response received on the /webhooks/recordings endpoint when the record action is used.

Prerequisites

Use your existing application

Install dependencies

Initialize your dependencies

Write the code

Add the following to app.js:

Copy to Clipboard
nexmo.files.save(RECORDING_URL, 'test.mp3', (err, res) => {
  if(err) { console.error(err); }
  else {
      console.log(res);
  }
});

View full source 

Run your code

Save this file to your machine and run it:

$ node app.js

Prerequisites

Use your existing application

Install dependencies

Initialize your dependencies

Write the code

Add the following to DownloadRecording.java:

Copy to Clipboard
nexmo.getVoiceClient().downloadRecording(RECORDING_URL).save("downloaded_recording.mp3");

View full source 

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following command to execute your application replacing com.nexmo.quickstart.voice with the package containing DownloadRecording:

gradle run -Pmain=com.nexmo.quickstart.voice.DownloadRecording

Prerequisites

Use your existing application

Install dependencies

Initialize your dependencies

Write the code

Add the following to index.php:

Copy to Clipboard
$recordingUrl = 'https://api.nexmo.com/v1/files/'.NEXMO_RECORDING_ID;
$data = $client->get($recordingUrl);
file_put_contents($recordingId.'.mp3', $data->getBody());

View full source 

Run your code

Save this file to your machine and run it:

$ php index.php

Prerequisites

Use your existing application

Install dependencies

Initialize your dependencies

Write the code

Add the following to get-recording.py:

Copy to Clipboard
response = client.get_recording(URL)
pprint(response)

View full source 

Run your code

Save this file to your machine and run it:

$ python3 get-recording.py > recording.mp3

Prerequisites

Use your existing application

Install dependencies

Initialize your dependencies

Write the code

Add the following to download-a-recording.rb:

Copy to Clipboard
response = client.files.save(RECORDING_URL, 'recording.mp3')

puts response.inspect

View full source 

Run your code

Save this file to your machine and run it:

$ ruby download-a-recording.rb

Try it out

You will need a Recording URL from which to download the recording file. You typically get this from the JSON response received on the /webhooks/recordings endpoint when the record action is used when recording a call, connecting another call and so on. A typical JSON response will resemble the following:

{'conversation_uuid': 'CON-ddddaaaa-bbbb-cccc-dddd-0123456789de',
 'end_time': '2018-08-10T11:19:31Z',
 'recording_url': 'https://api.nexmo.com/v1/files/aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
 'recording_uuid': 'ccccaaaa-dddd-cccc-dddd-0123456789ab',
 'size': 162558,
 'start_time': '2018-08-10T11:18:51Z',
 'timestamp': '2018-08-10T11:19:31.744Z'}
1.2.3.4 - - [10/Aug/2018 11:19:31] "POST /webhooks/recordings HTTP/1.1" 200 -

When you run the script, the recording located at the recording URL will be downloaded. You can then listen to the recording.