Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download recording #515

Open
hungthai1401 opened this issue Nov 2, 2018 · 9 comments
Open

Download recording #515

hungthai1401 opened this issue Nov 2, 2018 · 9 comments
Labels
code-generation issue deals with generated code difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@hungthai1401
Copy link

hungthai1401 commented Nov 2, 2018

Hello everybody,
Could you show me how can download the recording file to local drive?
Thanks & Best regard

@sh-ogawa
Copy link

sh-ogawa commented Nov 2, 2018

I am same problem.

`use Twilio\Rest\Client

$twilio = new Client($sid, $token);
$twilio->recordings('REXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,mp3')->fetch();`

recordings arguments add '.mp3', but '. json' at the end of url is forcibly added by the constructor of "Twilio\Rest\Api\V2010\Account\RecordingList" class's Constructor.

@hungthai1401
Copy link
Author

hungthai1401 commented Nov 2, 2018

@sh-ogawa Twilio document said:

Appending ".mp3" to the URI returns a binary MP3 audio file with mime-type type "audio/mpeg"

https://www.twilio.com/docs/voice/api/recording#fetch-a-recording-media-file

@sh-ogawa
Copy link

sh-ogawa commented Nov 2, 2018

Appending ".mp3" to the URI returns a binary MP3 audio file with mime-type type "audio/mpeg"

I know that.
What I want to know is there is no way to do it with this library? about it.

@hungthai1401
Copy link
Author

@sh-ogawa I don't know, too. Hope there will be other ways to do it

@childish-sambino
Copy link
Contributor

This is not currently supported by the Twilio helper libraries.

Adding it to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@childish-sambino childish-sambino added code-generation issue deals with generated code difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap labels Nov 27, 2019
@jkabat
Copy link

jkabat commented Oct 21, 2020

Hmm, unresolved for 2 years already... so we have to use hack like this:

foreach ($fetchedInbound->recordings->read() as $recording) {
    /** @var RecordingInstance $recording */
    $uri = sprintf('https://api.twilio.com%s', str_replace('.json', '', $recording->uri));
    ...
}

@hungthai1401
Copy link
Author

@jkabat I think this may is the only way at the current time

@akhil192502
Copy link

@jkabat where have you put this hack in? Also, does it work while downloading audio recording from a video call?

@davidkryzaniak
Copy link

require __DIR__ . '/vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = '';
$token = '';
$twilio = new Client($sid, $token);

$RecordingSid = $_REQUEST['RecordingSid'];
$file_type = '.mp3'; // or use '.wav'

$recording = $twilio->recordings($RecordingSid)->fetch();
$context = stream_context_create(["http"=>["header"=>"Authorization: Basic ".base64_encode("{$sid}:{$token}")]]);
$uri = 'https://api.twilio.com'.str_replace('.json',$file_type,$recording->uri);
$recording_file = file_get_contents($uri,false,$context);

file_put_contents($RecordingSid.$file_type,$recording_file); //saves the file in the current directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-generation issue deals with generated code difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

6 participants