# Context for recording - setting a filename and converting to MP3

**URL:** <https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058>\
**Category:** Asterisk Dialplan\
**Created:** [October 14, 2020, 12:00am UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058 "2020-10-14T00:00:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zermus](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@zermus](https://community.asterisk.org/u/zermus)\
**Post date:** [October 14, 2020, 12:00am UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/1 "2020-10-14T00:00:31Z")

</div>

Ok, so I’m working off old data from like Asterisk 1.3, but I’m trying to set a recording filename, then ring the extension (This is a context from a DB I have setup of numbers to record) and record the call, then have lame convert the file to MP3 once it’s done, however I don’t want it to record if nobody answers… Here is what I have, and I know I could be way off here…

```auto
exten => s,1,Set(FILENAME=${TIMESTAMP}-${CALLERID(number)})
exten => s,2,Set(MONITOR_EXEC_ARGS=&& nice -n 19 /usr/local/bin/lame -b 96 -t -F -m m --bitwidth 16 --quiet "/var/spool/asterisk/monitor/${FILENAME}.wav" "/var/spool/asterisk/monitor/${FILENAME}.mp3" && rm -f "/var/spool/asterisk/monitor/${FILENAME}.wav")
exten => s,3,MixMonitor(${FILENAME}.wav,b)
exten => s,4,Dial(PJSIP/302,24)
exten => s,5,Playback(number-not-answering)
exten => s,6,Playback(goodbye)
exten => s,7,Hangup()

```

Right now timestamp isn’t working and it’s throwing everything off I believe.

WORKING (Except for the ,b option)! USE THIS:

```auto
exten => s,1,Set(FILENAME=${STRFTIME(${EPOCH},,%m%d%Y-%H%M%S)}-${CALLERID(number)})
exten => s,2,Set(MONOPT=nice -n 19 /usr/local/bin/lame -b 16 --silent /var/spool/asterisk/monitor/${FILENAME}.wav /var/spool/asterisk/monitor/${FILENAME}.mp3 && rm -f /var/spool/asterisk/monitor/${FILENAME}.wav)
exten => s,3,MixMonitor(${FILENAME}.wav,b,${MONOPT})
exten => s,4,Dial(PJSIP/302,24)
exten => s,5,Playback(number-not-answering)
exten => s,6,Playback(goodbye)
exten => s,7,Hangup()

```

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [October 14, 2020, 9:43am UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/2 "2020-10-14T09:43:07Z")

</div>

Asterisk 1.3 doesn’t support PJSIP and there are other details that would be invalid in 1.3; did you mean 13?

TIMESTAMP: (Deprecated; use `${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})`

MIXMONITOR\_EXEC\_ARGS is not documented and seems unlikely to exist as MixMonitor provides a direct argument for this, and there is no need for a mixing command, as that is done on the fly.

If this were Monitor and MONITOR\_EXEC\_ARGS, it would be an out of specification use of the variable, as shell meta characters are not part of the arguments to the command being run.

I’m concerned about the use of “rm -f”. I suspect this is a bad habit (like kill -9) rather than needed.

---

<div class="post-metadata">

**Author:** ![zermus](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@zermus](https://community.asterisk.org/u/zermus)\
**Post date:** [October 14, 2020, 12:49pm UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/3 "2020-10-14T12:49:35Z")

</div>

> and there is no need for a mixing command, as that is done on the fly.

So MixMonitor supports MP3 encoding? How would I do this? What about something like this?

```auto
exten => s,1,Set(FILENAME=${STRFTIME(${EPOCH},,%m%d%Y-%H%M%S)}-${CALLERID(number)})
exten => s,2,Set(MONOPT=nice -n 19 /usr/local/bin/lame -b 16 --silent /var/spool/asterisk/monitor/${FILENAME}.wav /var/spool/asterisk/monitor/${FILENAME}.mp3 && rm -f /var/spool/asterisk/monitor/${FILENAME}.wav)
exten => s,3,MixMonitor(${FILENAME}.wav,b,${MONOPT})
exten => s,4,Dial(PJSIP/302,24)
exten => s,5,Playback(number-not-answering)
exten => s,6,Playback(goodbye)
exten => s,7,Hangup()

```

EDIT: YEP! This works. Thanks for the help with the date stamp!

Now for some reason my ,b option isn’t working and it records everything, even the “The number is not answering, goodbye”, though. ☹ I wish there were a way to make it not record if the phone isn’t picked up.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [October 14, 2020, 1:51pm UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/4 "2020-10-14T13:51:36Z")

</div>

Sounds like your service provider, or the callee’s, is answering the call. Asterisk cannot tell that apart from a genuine answer.

---

<div class="post-metadata">

**Author:** ![zermus](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@zermus](https://community.asterisk.org/u/zermus)\
**Post date:** [October 14, 2020, 2:18pm UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/5 "2020-10-14T14:18:05Z")

</div>

Well since I know it’s not the callee, that is somewhat disconcerting from my provider…

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [October 14, 2020, 2:19pm UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/6 "2020-10-14T14:19:08Z")

</div>

The callee’s network, not the callee.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [November 13, 2020, 2:19pm UTC](https://community.asterisk.org/t/context-for-recording-setting-a-filename-and-converting-to-mp3/86058/7 "2020-11-13T14:19:15Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
