Hi,
I’m working with Asterisk ARI and trying to understand how audio recording works. Specifically, are the audio packets written to the recording file only after the call ends, or are they written live as the call progresses? Any insights or experiences with this would be greatly appreciated!
Audio data is written to the open file as it occurs, but buffering can occur outside of Asterisk. If you’re trying to use it as a realtime stream it’s not meant for that.
I checked the recording file size one minute after starting, and it was zero. The size only updated after the call ended.
Asterisk itself doesn’t buffer. The functionality provided by the OS, which in many cases we use fwrite, can and does buffer. We don’t flush it to force the recording to be written out to disk in real time. On closure any buffer would be written to the file.
Isn’t it also the case that metadata is only written just before the file is closed, so, if the format includes metadata and the metadata includes the length of the actual media stream, I’d expect that to be zero, until the very last moment.
format_wav.c only updates the metadata on a close request or if its “trunc” method is invoked. I haven’t looked to see where trunc is used, but I assume it isn’t called for every frame.
It depends, but that can be the case depending on the file format.
Is there a way to have the recording file written in real time?
Laying aside that fact that it takes time to get from the input to recording media, that would be a fairly bad thing to do on modern machines, using SSD, as you would be turning over pages at around 50 pages per second per call, even though most of the page was unchanged. That would wear out the SSD relatively quickly.
You could have the code set the stream to unbuffered, and use a raw codec format, in which case, if the reading side was also set to unbuffered, you only get the serialisation delays associated with assembling frames (although actual the commit to physical media could be a few seconds later). That would mean modifying the relevant format modules.
Are you actually interested in the data being written to the file, or just in its being visible to other processes, on the same machine?
I would point out that any speech to text processing won’t work without some look ahead, and high quality transcriptions require several seconds of look ahead.
I want the recording file to be fully written by the time the StasisEnd event occurs.
However, in some cases the recording file is completed only after the StasisEnd event, and the RecordingFinished event is triggered after StasisEnd—even if I stop the recording before the channel hangup.
As a result, when I check the recording file at the moment the StasisEnd event is fired, the file is still not yet written.
StasisEnd is independent, and the recording is separate and asynchronous.
Why can’t you wait for RecordingFinished?
Yes, that’s what I’m doing currently, but I need to perform some actions when the StasisEnd event occurs. That’s why I was checking if there’s any way to access the recording data up to the point when StasisEnd is triggered.
Thanks, everyone, for your replies!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.