Asterisk can't find the sound files

Hello,

I can’t figure out why Asterisk can’t find the sounds files it recorded to playback. I’ve run the script on another server (Asterisk 1.8-r332699) and it ran just fine. I’ve created the files on the new server, changed the permissions and the directory paths. I can’t see what I’m missing. :confused:

I appreciate any insights!

Dialplan —>

[main_menu]
exten => start, 1, Set(step1count=0)
same => n(greeting),Answer()
same => n, Background(/usr/share/asterisk/sounds/en/dp_greeting)

same => n(beginning), Background(/usr/share/asterisk/sounds/en/dp_mainMenu)
same => n, WaitExten(8)

exten => 1, 1, Set(step2count=0) ; —> Leave to msgs
same => n(toLeave), Playback(/usr/share/asterisk/sounds/en/dp_leaveMsg)
same => n(record), Record(/var/spool//asterisk/tmp/newFile.gsm) ; to autosave on hangup = ,k

    same => n, Read(response,/usr/share/asterisk/sounds/en/dp_postLeaveMsg1, 1)
    same => n, GotoIf($["${response}" = "1"]?99,listen:)  ; --> go to listen, if like, save; if not, re-record
    same => n, GotoIf($["${response}" = "2"]?98,saveit:) ; ---> just go save it; leave another or listen to others
    same => n, GotoIf($["${response}" = "3"]?1,record:) ; ---> go to record
    same => n, GotoIf($["${response}" = "4"]?2,1:)   ; ----> go to listen to vms

exten => 99, 1(listen), Wait(1)
same => n, Playback(/var/spool/asterisk/tmp/newFile)
same => n, Verbose(did it play ${PLAYBACKSTATUS})
same => n, Read(responsePostListen,/usr/share/asterisk/sounds/en/dp_postLeaveMsg2, 1)
same => n, GotoIf($["${responsePostListen}" = “1”]?98,saveit:)
same => n, GotoIf($["${responsePostListen}" = “2”]?1,record:)
same => n, GotoIf($["${responsePostListen}" = “3”]?2,1:)

exten => 98, 1(saveit), Set(date=${STRFTIME(${EPOCH},%Y%m%d-%H%M-%S):-12})
same => n, System(mv /var/spool/asterisk/tmp/newFile.gsm /var/lib/asterisk/sounds/depo/${date}.gsm) ;
same => n, Set(__file=${date})
same => n, Verbose(file title is ${date}.gsm)
same => n, Playback(dp_thankyou)
same => n, Wait(1)
same => n, Goto(start,beginning)

exten => 2, 1, Set(step2count=0) ; ----> listen to msgs
;same => n(toListen), Read(direction,/usr/share/asterisk/sounds/en/dp_listenMsg,1)
same => n(toListen), Playback(/usr/share/asterisk/sounds/en/dp_listenMsg)
same => n, Goto(random,1,random)
same => n, GotoIf($["${direction}" = “1”]?random,1,random:) ; context,extension,label true:false
same => n, GotoIf($["${direction}" = “2”]?51,upBack:)

exten => i,1,Playback(db_invalid)
same => n, Goto(start,beginning)

exten => t,1,Playback(vm-goodbye)
same => n,Hangup()

[random]

exten => 1, 1(random), Verbose(we are going to play files randomly)
same => n(randie), Set(file=${SHELL(source /etc/asterisk/random.sh)})
same => n, Set(file=${file:0:12})
same => n, Verbose(“random file is ${file}”)
same => n(playback), Read(choice,/var/lib/asterisk/sounds/depo/${file},1)
;same => n, WaitExten(3)

    same => n, GotoIf($["${choice}" = "*"]?1,random:main_menu,start,beginning)

    same => n, Playback(vm-goodbye)
    same => n, Hangup()

exten => i,1,Playback(db_invalid)
same => n, Goto(main_menu,start,beginning)

exten => t,1,Playback(vm-goodbye)
same => n,Hangup()

CLI —>

Connected to Asterisk 1.8.4.4~dfsg-2ubuntu1 currently running on SonicProjects (pid = 1148)
we are going to play files randomly
random file is
[Mar 5 22:42:48] WARNING[1933]: file.c:644 ast_openstream_full: File /var/lib/asterisk/sounds/depo/ does not exist in any format
[Mar 5 22:42:48] WARNING[1933]: file.c:950 ast_streamfile: Unable to open /var/lib/asterisk/sounds/depo/ (format 0x4 (ulaw)): No such file or directory
SonicProjects*CLI>

Permissions -->

root@SonicProjects:/var/lib/asterisk/sounds# ls -la
total 16
drwxr-xr-x 4 asterisk asterisk 4096 2012-03-05 16:45 .
drwxr-xr-x 4 asterisk asterisk 4096 2012-03-05 22:42 …
drwxr-xr-x 2 asterisk asterisk 4096 2011-09-23 05:58 custom
drwxrwxrwx 2 asterisk asterisk 4096 2012-03-05 21:35 depo

  • Asterisk 1.8.4.4 on Ubunto 11.10 - LAMP

Your CLI output states that the file variable is empty therefore the Read command is failing because it is getting only a directory with no file. Check that your ’ /etc/asterisk/random.sh’ script is working properly.

Are the other sounds in the menu playing properly?

Hi dalenoll,

I noticed that as well. The random.sh script does work properly. My other sounds are playing. It’s puzzling. :confused:

Can you post the shell script?

Sure…

#!/bin/bash

files=(*.gsm) # Or *.gif, or *

n=${#files[@]} # For aesthetics

xmms – “${files[RANDOM % n]}” # Choose a random element

shuf -n1 -e *

ls -l shuf -n l

#find . | shuf -n1

cd /var/lib/asterisk/sounds/depo
a=(*); echo ${a[$((RANDOM % ${#a[@]}))]}

Ok. I put your script on my server and tested with the existing files in the /var/lib/asterisk/sounds/en directory.

It didn’t work… fr a couple of reasons.

  1. The script returns the filename including the extension. This is considered wrong in Asterisk. The filename should not have an extension(for Read, Playback and Background) and it will look at the different file formats and play the most appropriate one.

  2. The echo command includes an embedded ‘newline’ character which the SHELL() function is including in the value. So the file name that was being requested was ‘filename.ext\n’.

I made the following change to the last line of your script and it started working for my testing.

Now that does not answer why you are getting a blank value in the variable.

Here is my version of the ‘randomfile.sh

#!/bin/bash
# files=(*.gsm) # Or *.gif, or *
# n=${#files[@]} # For aesthetics
# xmms -- "${files[RANDOM % n]}" # Choose a random element

# shuf -n1 -e *

# ls -l shuf -n l

#find . | shuf -n1

cd /var/lib/asterisk/sounds/en
a=(*); echo -n ${a[$((RANDOM % ${#a[@]}))]} | sed 's/\.[a-z]*$//'

Here is my dialplan that I used for testing

exten	=> 650,1,NoOp(Testing SHELL)
 same	=> n,Set(file=${SHELL(source /etc/asterisk/randomfile.sh)})
 same	=> n,NoOp(File: ${file})
 same	=> n(playback),Playback(/var/lib/asterisk/sounds/en/${file})
 same	=> n,Read(choice,/var/lib/asterisk/sounds/en/${file},1)
 same	=> n,NoOp(Choice: ${choice})
 same	=> n,hangup()

I hope this helps

Hello,

I really appreciate you taking the time to look at this, revise the script and to try it out yourself.

In regards to #1, I have the line

   same => n,Set(file=${file:0:12})

to truncate the extension off the filename. I know that Read, Playback and Background don’t like them.

In regards to #2, I did amend my shell script as you outlined, commented out the line mentioned above, and still not luck.

I even tried your dialplan and this is what the CLI gave me ---->

we are going to play files randomly
[Mar 6 16:16:57] WARNING[4206]: file.c:644 ast_openstream_full: File /var/lib/asterisk/sounds/depo/ does not exist in any format
[Mar 6 16:16:57] WARNING[4206]: file.c:950 ast_streamfile: Unable to open /var/lib/asterisk/sounds/depo/ (format 0x4 (ulaw)): No such file or directory
[Mar 6 16:16:57] WARNING[4206]: app_playback.c:471 playback_exec: ast_streamfile failed on SIP/sip.broadvoice.com-00000001 for /var/lib/asterisk/sounds/depo/
[Mar 6 16:16:57] WARNING[4206]: file.c:644 ast_openstream_full: File /var/lib/asterisk/sounds/depo/ does not exist in any format
[Mar 6 16:16:57] WARNING[4206]: file.c:950 ast_streamfile: Unable to open /var/lib/asterisk/sounds/depo/ (format 0x4 (ulaw)): No such file or directory

When I did a module reload, I got this —>

[Mar 6 16:23:11] NOTICE[1860]: chan_skinny.c:7209 config_load: Configuring skinny from skinny.conf
[Mar 6 16:23:11] NOTICE[1860]: app_queue.c:6469 reload_queue_rules: queuerules.conf has not changed since it was last loaded. Not taking any action.
[Mar 6 16:23:11] NOTICE[1860]: res_config_ldap.c:1631 parse_config: No directory user found, anonymous binding as default.
[Mar 6 16:23:11] ERROR[1860]: res_config_ldap.c:1657 parse_config: No directory URL or host found.
[Mar 6 16:23:11] NOTICE[1860]: res_config_ldap.c:1591 reload: Cannot reload LDAP RealTime driver.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:122 pbx_load_module: Starting AEL load process.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:135 pbx_load_module: AEL load process: parsed config file name ‘/etc/asterisk/extensions.ael’.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:138 pbx_load_module: AEL load process: checked config file name ‘/etc/asterisk/extensions.ael’.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:145 pbx_load_module: AEL load process: compiled config file name ‘/etc/asterisk/extensions.ael’.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:150 pbx_load_module: AEL load process: merged config file name ‘/etc/asterisk/extensions.ael’.
[Mar 6 16:23:11] NOTICE[1860]: pbx_ael.c:153 pbx_load_module: AEL load process: verified config file name ‘/etc/asterisk/extensions.ael’.

I’m not sure if that’s related.

I even changed the permissions on the parent directory (no luck), moved the file to a different directory (same directory as the sample sound files) and still no luck.

I’m lost. Is it related to the install, perhaps?

It is odd. When I see odd things happening that I have not other explanation I ask ‘Is SELinux turned on?’

No…it’s turned off.

I’m running this on Rackspace.

Heck. It was worth a shot.

OK. Can you ‘su - asterisk’ on the box? (of course, if asterisk is running under some other username, use it instead)

Can you cd into the directory where the audio files are as this non-root user?

If you can can up ‘od’ one of the files in question?

If that works, then I have to go back to the script which may not be returning the a value. Can you source the script as the non-root user? Does it do what is expected?

How about you change the dialplan and instead of ‘source’ the script into the shell that Asterisk creates, feed it into a new subshell by calling like this: Set(file=${SHELL(bash /etc/asterisk/randomfile.sh)})

I tried everything you suggested. I could see the sound files as a non-root user, and run the script properly.

BUT, when I changed the “source” to “bash”, everything worked as before!!!

Hooray!!! Thank you! :smiley:

Glad to hear it is working. Happy to be of service to you.

The SHELL() function must be calling a different shell than bash.

Make me want to do a Set(shell=${SHELL(echo $SHELL)})