Playback/background Audio From MySQL BLOB

Home » Asterisk Users » Playback/background Audio From MySQL BLOB
Asterisk Users 9 Comments

For some applications, storing recorded audio (prompts and caller recordings) as a BLOB in MySQL has advantages.

So, once I have the audio in the database, how can I play it?

Creating temporary files seems so tacky.

Is there another way to playback or background audio either by specifying a URL or from a memory buffer (either C or PHP)?

9 thoughts on - Playback/background Audio From MySQL BLOB

  • How about a named pipe (fifo)? Of course then you might have issues with simultaneous calls. You would have to have a pool of them and somehow manage locking them…

    j

  • Jeff sez:
    How about a named pipe (fifo)? Of course then you might have issues with simultaneous calls. You would have to have a pool of them and somehow manage locking them…

    J

    I’m curious about what the advantages are of storing audio in a blob. Wouldn’t it be more efficient to store it in a file and just put the filename in the database?

    –Don

  • Multiple web servers, multiple Asterisk servers, multiple DB servers, synchronizing filesystems vs db, etc.

    It appears to eliminate some problems, but Asterisk limiting audio playback to files seems like a tough obstacle.

  • Maybe make the audio files available to all servers via a single NFS
    directory? Probably not a good solution if the servers aren’t co-located.

  • Mike said:
    Maybe make the audio files available to all servers via a single NFS
    directory? Probably not a good solution if the servers aren’t co-located.

    Maybe someone could write a Linux device “file” that would return the blob’s content as a file read.

    –Don

  • Depending how many messages you have, you could use a named pipe (FIFO) or a Unix-domain socket for each one; and have the individual backend processes interrogate the database and dump the contents of the relevant field down it.
    As far as Asterisk is concerned, the socket / FIFO looks just like a file; it doesn’t care much that the data in it is really coming from a process on the other end. This obviously suffers from the problem of decreasing manageability, the more message “files” you have.

    But personally, I’d just store the filenames in the database; and rely on the unix filesystem for storing the actual file contents. After all, that’s what a filesystem is for.

  • This.

    Shocking as it might appear, filesystems are remarkably good at storing files. They were designed to do it. Why try to shoehorn a database into doing something it wasn’t designed to do (and isn’t particularly good at doing)?

    Kind regards,

    Chris

  • I beat you to that one 😉 That is exactly what a named pipe (fifo) is.
    Asterisk would read it like a sound file, and the AGI would dump the BLOB to it on demand. It would work, but you can’t have more than one process at a time reading from it, so that’s a further complication…

    j