Amir Nejatbakhsh
Amir Nejatbakhsh

Reputation: 51

How to play asterisk's recorded calls from a php application?

I have an Issable (Asterisk based VoIP solution) in my company. I am developing an application in PHP which part of it I need to play the recorded calls. the application is located in a separate server from the Issabel. I already have access to the sound file path which for example is:

/var/spool/asterisk/monitor/2018/10/20/rg-600-2122238507-20181020-223323-1540062203.100880.wav

When I want to play this file using HTML's audio tag by adding the ip address of the issabel server at the beginning of this path, nothing happens and even the Isaabel blocks my IP address since the server is password protected. Any solution to play the file located in this path from my PHP application would be appreciated.

Upvotes: 1

Views: 1858

Answers (1)

Amir Nejatbakhsh
Amir Nejatbakhsh

Reputation: 51

As FélixGagnon-Grenier mentioned the solution to this problem is solved by streaming the audio to the application. I have created stream.php in the server containing the following code:

 <?php
    $filePath = $_GET['file'];
    $fileName = basename($filePath);
    $fp=fopen($filePath, "rb");
    header("Content-type: application/octet-stream");
    header('Content-disposition: attachment; filename=$fileName');
    header("Content-transfer-encoding: binary");
    header("Content-length: ".filesize($filePath)."    ");
    fpassthru($fp);
    fclose($fp);

and in my application which is located in another server I used HTML5 audio tag to call the file and send the path to the audio file with GET method:

<audio controls>
<source src="https://<SERVER_IP>/stream.php?file='.$callRecordPath.'" type="audio/wav">
Your browser does not support the audio element.
</audio> 

and it worked for me! Thanks

Upvotes: 3

Related Questions