This guide shows how to retrieve recordings and download them to local storage. Plivo begins charging for stored recordings after 90 days. To avoid these charges, you can download recordings and store them elsewhere.
To use Plivo APIs, follow our instructions to set up a python development environment and a web server and safely expose that server to the internet.
Here’s sample code you can use to retrieve recordings to a local directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import plivo
import requests
import os
AUTH_ID = "<auth_id>"
AUTH_TOKEN = "<auth_token>"
client = plivo.RestClient(AUTH_ID,AUTH_TOKEN)
response = client.recordings.list(
add_time__gt='2023-07-01 00:00:00',
add_time__lt='2023-07-30 00:00:00',
offset=0,
limit=5,
)
print(f"Found {len(response)} recordings.")
# Directory where the recordings will be saved
path = 'recordings'
os.makedirs(path, exist_ok=True)
for i, recording in enumerate(response):
url = recording['recording_url']
print(f"Downloading recording: {url}")
# Download the file
r = requests.get(url)
file_path = os.path.join(path, f'{recording["recording_id"]}.{recording["recording_format"]}')
with open(file_path, 'wb') as f:
f.write(r.content)
print(f"Downloaded file to: {file_path}")
You can delete a recording by using the Delete a Recording API and specifying a recording ID, which you can retrieve from list all recordings API or the HTTP callback details stored in your database. You can also delete recordings from the Voice Recordings page of the Plivo console.