Download a recording
In this code snippet you see how to download a recording.
Example
Replace the following variables in the example code:
| Key | Description |
|---|---|
VOICE_RECORDING_URL | The URL of the recording to download. You typically get this from the JSON response received on the |
Prerequisites
Execute the following command at your terminal prompt to create the JWT for authentication:
export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)Write the code
Add the following to download-a-recording.sh:
curl $VOICE_RECORDING_URL \
-H "Authorization: Bearer $JWT" \
--output recording.mp3Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-clientCreate a file named download-a-recording.js and add the following code:
const { FileClient } = require('@vonage/server-client');
const fileClient = new FileClient({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to download-a-recording.js:
fileClient.downloadFile(
VOICE_RECORDING_URL,
VOICE_RECORDING_DESTINATION,
)
.then(() => console.log(`File Downloaded to ${VOICE_RECORDING_DESTINATION}`))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named DownloadRecording and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the DownloadRecording class:
val destination = Paths.get("/Users/me123/Downloads")
client.voice.downloadRecording(VOICE_RECORDING_URL, destination)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 gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing DownloadRecording:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named DownloadRecording and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the DownloadRecording class:
/*
* A recording webhook endpoint which automatically downloads the specified recording to a file in the
* current working directory, called "downloaded_recording.mp3"
*/
Route downloadRoute = (req, res) -> {
EventWebhook event = EventWebhook.fromJson(req.body());
String recordingUrl = event.getRecordingUrl().toString();
Path recordingFile = Paths.get("downloaded_recording.mp3");
System.out.println("Downloading from " + recordingUrl);
client.getVoiceClient().saveRecording(recordingUrl, recordingFile);
return "OK";
};
Spark.port(3000);
Spark.post("/recording", downloadRoute);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 gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing DownloadRecording:
Prerequisites
Install-Package VonageWrite the code
Add the following to GetRecording.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);
var response = await client.VoiceClient.GetRecordingAsync(VOICE_RECORDING_URL);Prerequisites
composer require vonage/clientRun your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvWrite the code
Add the following to get-recording.py:
from vonage import Auth, Vonage
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
)
)
client.voice.download_recording(VOICE_RECORDING_URL, 'recording.mp3')Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageRun your code
Save this file to your machine and run it:
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.
Further Reading
- Transcription - This guide shows you how to use the Amazon Transcribe API to transcribe a phone conversation recorded with the Vonage Voice API.