How to browse through multiple audio files for playback on Asterisk dialplan from phone?

I’m trying to make a voicemail system on Asterisk 16, FreePBX 16 and CentOS 7 that lets people browse and choose from a list of prerecorded audio files. When the caller enters the menu to select the audio files, they’re told how to browse through the different files. In the /var/lib/asterisk/sounds/ directory, the files are named from 1 to 3 (1.wav, 2.wav etc.) currently and the caller presses 1 to go to the previous file and 2 to go to the next file and 3 to select the current file they’re listening to. The extensions.conf part goes as such:

[prerecorded]
exten = s,1,NoOp(Pre-recorded messages)
same = n,Set(LOOP=0)
same = n,Set(FILE=1)
same = n(timeout),Wait(1)
same = n,Playback(browsing_tutorial)
same = n(loop),NoOp(Loop)
same = n,Background(${FILE})
same = n,WaitExten(5)

exten = 1,1,NoOp(Previous file)
same = n,Set(FILE=$[ ${FILE} - 1])
same = n,GoToIf($[ ${FILE} = 0 ]?:s,loop)
same = n,Playback(first_file)
same = n,Set(FILE=1)
same = n,GoTo(s,loop)

exten = 2,1,NoOp(Next file)
same = n,Set(FILE=$[ ${FILE} + 1])
same = n,GoToIf($[ ${FILE} = 4 ]?:s,loop)
same = n,Playback(last_file)
same = n,Set(FILE=3)
same = n,GoTo(s,loop)

exten = #,1,NoOp(Repeat)
same = n,GoTo(s,1)

exten = t,1,NoOp(No input)
same = n,Set(LOOP=$[ ${LOOP} + 1 ])
same = n,GoToIf($[ ${LOOP} > 2 ]?:s,timeout)
same = n,HangUp()

Doing it this way lets me browse through the files, but it warrants editing the extensions every time I add or remove any prerecorded files (which will be done often). If there’s any way I can do this without needing to edit the extensions, it would be great.

You can use ${SHELL} along with one of the standard Linux tools to list the files and determine the last one.

1 Like

Try store audio files name into “string” comma separated and use its index to navigate.
Use SHELL function to retrieve file names and FIELDQTY to get amount of file names stored.
With this way you don’t need to care after delete some file or add new one.

1 Like

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