twiliocall-recording

Twilio: Issue with call record mp3 file in call logs


I'm using this API for getting the Twilio call logs. I want the recording for the corresponding call as an mp3 file. We are accessing recording URLs from the recordings under subresource_uris but that is the .json file. As per this thread, we replaced .json with .mp3 and added https://api.twilio.com at the beginning. If we try to play the recording it is not playing.

Currently, the recording URL is available for all call logs but only a few of the calls have enabled the call record. So how we can distinguish a call is recorded or not?


Solution

  • Twilio developer evangelist here.

    From what I can tell, you are trying to access recording files for calls in C#. You can get a list of recordings for a call by requesting the call's recording resource:

    string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
    string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
    
    TwilioClient.Init(accountSid, authToken);
    
    var recordings = RecordingResource.Read(
      callSid: "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      limit: 20
    );
    
    // print out each recording's URI
    foreach(var record in recordings)
    {
      Console.WriteLine(record.Uri);
    }
    

    If you run the above with a call Sid that has recordings then you will see the URIs of the recording's printed out. They will look like:

    /2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings/REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json
    

    This is the URI you should take, prefix with https://api.twilio.com and change the extension from .json to .mp3 in order to get the recording file. So, for the above example, requesting:

    https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings/REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mp3
    

    So, if you use the API to get the call logs to get the Call SIDs, then call on each call's recordings resource you can then get the list of recordings and construct the URI to download each recording audio file.