How to create an MP3 recording with Voice API in Python How to create an MP3 recording with Voice API in Python

How to create an MP3 recording with Voice API in Python

Vonage API Support

Objective

How to create a recording of a Voice API call in MP3 format.

Applies To

  • Voice API
  • Python SDK

Procedure

  1. You can follow the steps to get the recording into a variable within your Python script.
  2. Once you have the audio in a variable (recording) in the example below, you can write it to a file using the code following the comment: # how to write recording to file.
recording = voice.get_recording("https://api-us.nexmo.com/v1/files/example-9009-4412-a31c-8380fcad6ac2")

# how to write recording to file
file = 'recording.mp3'

with open(file, 'wb') as f:
f.write(recording)

You now have your recording in an MP3 file named 'recording.mp3' on disk, which can be played on any popular MP3 player.