Browsing through multiple audio files for playback on Asterisk dialplan - centos7

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 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 write your own application using native C/C++ interface in asterisk, if you skilled enough. See app_voicemail.c
You also can use AGI or ARI interface and control dialplan with scripted language
Other option is voicemail storage in db and db-driven app using func_odbc

Related

AWS Python script (Rekognition) working when called from command line, but not automatically

i am working on a script which uploads pictures to S3 and then adds that picture to a rekognition collection. When i run this script from the command line everything works perfectly - no issues. However, when the system executes it automatically (the script runs whenever a new file is added to the specified upload folder) the rekognition portion of the code does not run. Everything up through os.remove works fine automatically, but i can't get the images added to the collection. After days of messing with the code i am looking for some help - please let me know if i am missing something here.
After messing around with the script a bit and debugging it is client=boto3.client('rekognition') which for some reason does not allow the script to run. Any thoughts on why that would be?
import boto3
import os
#Get file name of newly uploaded picture
path = "/var/www/html/upload/webcam-capture/"
files = os.listdir(path)
for name in files:
#Split up file name for proper processing
components = name.split('-')
schoolName = components[0]
imageType = components[1]
idNumber = components[2]
# Upload files to bucket with Python SDK
s3 = boto3.resource('s3')
s3.meta.client.upload_file(path + name, schoolName + '-' + imageType + '-' + 'media.XXX.school', idNumber)
# Delete file from webcam-capture temp folder
os.remove (path+name)
#Add Face to Facial Recognition Collection
collection_id = schoolName + '-' + imageType
bucket= collection_id + '-media.XXX.school'
client=boto3.client('rekognition')
response=client.index_faces(CollectionId=collection_id,Image={'S3Object':{'Bucket':bucket,'Name':idNumber}},MaxFaces=1,QualityFilter="AUTO",DetectionAttributes=['ALL'])```

Python-Multiprocessing Error when working with astropy

I want to speed up some scripts that I need to analyze astronomical data. I have scripts that are run independently for every single image file that I have (which are in .fits file format). I was trying to simply start multiple files at once using Multiprocessing.Pool() and map. My code looks like this:
def sextract(name):
# creates a class instance and calls the method
astro = astrometry(name, *some_more_args)
astro.sextract()
arguments = ['PART1_cal.fits', 'PART2_cal.fits', 'PART3_cal.fits',
'PART4_cal.fits', 'PART5_cal.fits']
with closing(Pool()) as pool:
pool.map(sextract, arguments)
pool.terminate()
and the astrometry.sextract method looks like this:
def sextract(self):
sex = 'sextractor'
headerlist = ['JD-START', 'OBSERVER', 'DATE', 'TM-START', 'OBJECT',
'FLTRNAME', 'RA', 'DEC', 'AIRMASS',
'EXP_TIME']
calib = self._from
# calls the SourceExtrator in the shell with a config-file and
# the file name
os.system(sex + ' -c ' + self.sexpath + ' ' + calib)
# copies the extracted file to a folder on an external HDD
shutil.copy2(self.ext_path, self._to + '/' +
calib.split('/')[-1])
# opens the old .fits image and extracts the header
old = fits.open(calib)
o = old[0].header
# opens the new(copied) .fits image and extracts the header
# this produces the error
extr = fits.open(self._to + '/' + calib.split('/')[-1],
mode='update')
e = extr[1].header
# goes through the old header entries and copies all entries
# in the to the new header
for g in headerlist:
e[g] = o[g]
# saves the new header to the new(copied) file and closes both
# files
extr[1].header = e
extr.flush()
extr.close()
old.close()
Every time I run this code, I get an IOError: Header missing END card., which is thrown by the line where I open the new .fits and put it in the variable extr. At first I thought this would happen because the copy procedure would take too long, and the python tries to access the file before it's finished copying. I inserted a time.sleep(10) to check that, but the error still appears.
I tried using pool.apply() and the normal map() and in both cases I don't get an error. When using pool.apply() it takes almost as long as for the map() case though, so I haven't really accomplished anything doing it this way.
I know this is a very specific question, but I hope someone might know where my problem lies, or got something similar working already.

Downloading data from website

I use the following code for downloading two files in a folder from a website.
I want to download some files that contain "MOD09GA.A2008077.h22v05.005.2008080122814.hdf" and "MOD09GA.A2008077.h23v05.005.2008080122921.hdf" in the page. But I don't know how to select these files. The code below download all the files, but I only need two of them.
Does anyone have any ideas?
URL = 'http://e4ftl01.cr.usgs.gov/MOLT/MOD09GA.005/2008.03.17/';
% Local path on your machine
localPath = 'E:/myfolder/';
% Read html contents and parse file names with ending *.hdf
urlContents = urlread(URL);
ret = regexp(urlContents, '"\S+.hdf.xml"', 'match');
% Loop over all files and download them
for k=1:length(ret)
filename = ret{k}(2:end-1);
filepathOnline = strcat(URL, filename);
filepathLocal = fullfile(localPath, filename);
urlwrite(filepathOnline, filepathLocal);
end
Try the regexp with tokens instead:
localPath = 'E:/myfolder/';
urlContents = 'aaaa "MOD09GA.A2008077.h22v05.005.2008080122814.hdf.xml" and "MOD09GA.A2008077.h23v05.005.2008080122921.hdf.xml" aaaaa';
ret = regexp(urlContents , '"(\S+)(?:\.\d+){2}(\.hdf\.xml)"', 'tokens');
%// Loop over each file name
for k=1:length(ret)
filename = [ret{k}{:}];
filepathLocal = fullfile(localPath, filename)
end

ZIP Archive Created Within ZIP Archive

I recently wrote a python script to select certain files within a directory and save them to a new archive within that directory. The script works with the exception that it creates a duplicate archive within the new archive. I think it has something to do with the arcname I used and the loop but I'm really not sure. As I'm sure is obvious by looking at my code I am a beginner so I am sure there is plenty of room for improvement here. Any ideas as to where the problem is? Also if you have any suggestions for improving the code I'm all ears.
import os,arcpy,zipfile
inputfc = arcpy.GetParameterAsText(0) # User Inputs Feature Class Path
desc = arcpy.Describe(inputfc)
fcname = desc.basename
zname = fcname + ".zip"
gpath = os.path.dirname(inputfc)
zpath = os.path.join(gpath,zname)
zfile = zipfile.ZipFile(zpath, "w")
for f in os.listdir(gpath):
fpath = os.path.join(gpath, f)
if f.startswith(fcname):
zfile.write(fpath,f,compress_type = zipfile.ZIP_DEFLATED)
zfile.close()
Edit: After aruisdante answered my question I decided to just change the zname variable to
zname = "zip" + fcname + ".zip" #ugly but it worked thanks
This:
zfile = zipfile.ZipFile(zpath, "w")
Creates a new Zip file at zpath
for f in os.listdir(gpath):
Iterates through all of the files at gpath. Since gpath is also the root of zpath, then the zip file you just created will be one of the files in gpath. So it gets included in the archive. You will need to exclude it:
for f in (filename for filename in os.listdir(gpath) if filename != zname):

py2app - preserve directory structure

I would like to make a mac os x app for distributing my program.
The problem is that current script puts "images/Diagram.png" and other files under "images" folder to "Resources" but not to "Resources/images" as expected
What can I change in this setup.py part in order to put png files under images?
mainscript, ico, icns = "aproxim.py", "sum.ico", "sum.icns"
files = ["images/Diagram.png", "images/document.png", "images/Exit.png", "images/floppydisc.png",
"images/folder.png", "images/Info.png", "images/settings.png"]
scripts = ["app_settings_dialog", "app_window", "approximator", "approximator2", "data_format",
"easy_excel", "functions", "main_window", "settings_dialog",
"util_data", "util_parameters"]
description = "Approximator is program for experimental data approximation and interpolation (20 dependencies for select)"
common_options = dict(name = "Approximator", version = "1.7", description = description)
if sys.platform == 'darwin':
setup(
setup_requires = ['py2app'],
app = [mainscript],
options = dict(py2app = dict(includes = scripts, resources = files, iconfile = icns)),
**common_options)
It is easy, hope it is useful for other Python developers:
resources = [('images', files), ('', [ico])]