News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Retrieve Call MP3 / WAV - Python
Tags: sdk, rest api, call recording
Apr 28, 2022 at 7:35am   •   1 replies  •  0 likes
Nate Breeden

We have an automation for our IT tickets, when an agent hangs up with a caller it creates a ticket and then links to RingCentral's call recording for the call to listen to later.

What we would like to do is dump the recording as an attachment to that ticket/email, this would allow us to keep recordings longer.

How am I able to do that? We looked through "Get Call Recordings Data" (https://developers.ringcentral.com/api-reference/Call-Recordings/listCallRecordingData) but are not sure how to take that data in Python and save it as a MP3/WAV file.

We have tried taking r.text() and exporting the bytes to a WAV file, but then it returns that r.text() is does not contain only byes(which it doesn't). We have tried loading r.text() into pydub as well, but it does not read it either.

Is this not possible with Python?

1 Answer
answered on Apr 28, 2022 at 9:42am  

Here is the sample code for you Nate. If you need to read the call log and download lots of call recordings, you will need to handle the API rate limit. If you need to detect the file format as wav or mp3, you need to read the recording metadata and detect the type to create a correct filename extension.

 def read_account_call_log():
     path = os.getcwd() + "/recording_content/"
     if not os.path.isdir(path):
         print("create folder")
         try:
             os.mkdir(path)
         except OSError as e:
             print(e)
    
     params = {
         'dateFrom': "2022-01-01T00:00:00.000Z",
         'perPage': 1000
     }
     resp = platform.get('/restapi/v1.0/account/~/call-log', params)
     jsonObj = resp.json()
     for record in jsonObj.records:
         if hasattr(record, 'recording'):
             fileName = str(record.recording.id) + ".mp3"
             try:
                 res = platform.get(record.recording.contentUri)
                 file = open(("%s%s" % (path, fileName)),'wb')
                 file.write(res.body())
                 file.close()
                 print ("Call recording saved in " + fileName)
             except ApiException as e:
                 print (e.getMessage())

 0
on Apr 28, 2022 at 10:16am   •  0 likes

You're awesome as always, Phong! Thank you!



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us