Streaming a longblob to Asterisk


#1

I have a database storing my voicemail messages via ODBC into mysql, with the recording stored as a longblob. What I would like to do, is have a little app that retrieves a message by message number and then plays it back to the caller. Do I have to write this to a temporary file and then stream the file back, or is there a way to stream the longblob back to the caller via the dialplan?


#2

In the meantime, I have done this:

[code]#!/usr/bin/php -q

<?php // Write temporary .WAV file from longblob in MySQL // Include database connection details include("ast_db_connects.php"); // Invoke Asterisk PHP Library require("phpagi.php"); $agi = new AGI(); //==================================================== //Various program functions //==================================================== // Get Recording //**************** function getRecording($db_link, $msg_num){ $query_str = 'SELECT recording FROM voicemessages WHERE msgnum='.$msg_num; $db_res = mysql_query($query_str); $msg_recording = mysql_result($db_res, 0, "recording"); return($msg_recording); } //**************** //==================================================== //Main body of program //==================================================== // Initialize database $db_link = init_db(); @mysql_select_db($db_name) or die("Unable to select database"); $collection_array = $agi->get_variable(msg_num); $msg_num = $collection_array['data']; $recording = getRecording($db_link, $msg_num); //write wav49 format from longblob in MySQL database $fname = "/var/lib/asterisk/sounds/playback_tmp/".$msg_num.".WAV"; $h = fopen($fname, "wb"); fwrite($h, $recording); fclose($h); mysql_close($db_link); ?>[/code]

But would love to be able to stream directly w/o having to create a temporary file.


#3

If you are talking php output to http/browser, you should be able to read the blob just like any other row of data and echo/return the result. The biggest thing would be using the php headers function and changing the Content-type to the appropriate type i.e. header("Content-type: audio/wav"); when sending it back to the browser, so it knows how to handle it. I’m no expert but i think that would do it.

hth,


#4

I do not want to echo to the browser but to an Asterisk stream for playback.


#5

I do not believe it is possible via AGI. While using extended AGI (EAGI) allows you to read a channel, it does not appear to allow write to a channel (from looking at the C code).