ivr wrapper for audio mixin and example app

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@395 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 19 years ago
parent 8bc40b2f64
commit 7bebf15237

@ -29,6 +29,8 @@
#include "AmConfig.h"
#include "AmUtils.h"
#include "AmAudioMixIn.h"
#include "sems.h"
#include "log.h"
@ -119,8 +121,15 @@ void AnnouncementDialog::startSession(){
if(wav_file.open(filename,AmAudioFile::Read))
throw string("AnnouncementDialog::onSessionStart: Cannot open file\n");
setOutput(&wav_file);
DBG("*************************asdasdasdasd*********\n");
AmAudioFile* f = new AmAudioFile();
if (f->open("/tmp/beep.wav", AmAudioFile::Read)) {
throw string("AnnouncementDialog::onSessionStart: Cannot open file\n");
}
AmAudioMixIn* s = new AmAudioMixIn(&wav_file, f, 4, 0.0);
setOutput(s);
}
void AnnouncementDialog::onBye(const AmSipRequest& req)

@ -0,0 +1,14 @@
NAME=mix_announce
VERSION=0.0.1
PYTHON_VERSION=2.4
LIBDIR=
COREPATH=../../../core
IVRPATH=../../ivr
# general python app Makefile
include $(IVRPATH)/Makefile.ivr_application

@ -0,0 +1,2 @@
announcement=../apps/voicemail/wav/default_en.wav
beep=../apps/voicemail/wav/beep.wav

@ -0,0 +1,2 @@
import compileall
compileall.main()

@ -24,6 +24,7 @@
#include "IvrSipRequest.h"
#include "IvrSipReply.h"
#include "IvrAudio.h"
#include "IvrAudioMixIn.h"
#include "IvrUAC.h"
#include "Ivr.h"
@ -240,6 +241,9 @@ void IvrFactory::import_ivr_builtins()
// IvrAudioFile
import_object(ivr_module,"IvrAudioFile",&IvrAudioFileType);
// IvrAudioMixIn
import_object(ivr_module,"IvrAudioMixIn",&IvrAudioMixInType);
// IvrUAC
import_object(ivr_module,"IvrUAC",&IvrUACType);

@ -0,0 +1,131 @@
#include "IvrAudioMixIn.h"
#include "IvrAudio.h"
#include "log.h"
static PyObject* IvrAudioMixIn_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
DBG("---------- IvrAudioMixIn_alloc -----------\n");
IvrAudioMixIn *self;
self = (IvrAudioMixIn *)type->tp_alloc(type, 0);
if (self != NULL) {
self->mix = NULL;
}
return (PyObject *)self;
}
static void IvrAudioMixIn_dealloc(IvrAudioMixIn* self)
{
DBG("---------- IvrAudioMixIn_dealloc -----------\n");
if (self->mix) {
delete self->mix;
self->mix = NULL;
}
self->ob_type->tp_free((PyObject*)self);
}
static PyObject* IvrAudioMixIn_init(IvrAudioMixIn* self, PyObject* args)
{
AmAudioFile* a = NULL;
AmAudioFile* b = NULL;
int s;
double l;
PyObject *o_a, *o_b;
if(!PyArg_ParseTuple(args,"OOid", &o_a, &o_b, &s, &l))
return NULL;
if (o_a == Py_None) {
PyErr_SetString(PyExc_TypeError,"Argument 1 is None (need IvrAudioFile)");
return NULL;
}
if (o_b == Py_None) {
PyErr_SetString(PyExc_TypeError,"Argument 2 is None (need IvrAudioFile)");
return NULL;
}
if(!PyObject_TypeCheck(o_a,&IvrAudioFileType)){
PyErr_SetString(PyExc_TypeError,"Argument 1 is no IvrAudioFile");
return NULL;
}
a = ((IvrAudioFile*)o_a)->af;
if(!PyObject_TypeCheck(o_b,&IvrAudioFileType)){
PyErr_SetString(PyExc_TypeError,"Argument 2 is no IvrAudioFile");
return NULL;
}
b = ((IvrAudioFile*)o_b)->af;
if (NULL !=self->mix) {
delete self->mix;
}
self->mix = new AmAudioMixIn(a, b, s, l);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef IvrAudioMixIn_methods[] = {
{"init", (PyCFunction)IvrAudioMixIn_init, METH_VARARGS,
"open the mixin with two audio files, interval and level"
},
{NULL} /* Sentinel */
};
static PyGetSetDef IvrAudioMixIn_getseters[] = {
{NULL} /* Sentinel */
};
PyTypeObject IvrAudioMixInType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"ivr.IvrAudioMixIn", /*tp_name*/
sizeof(IvrAudioMixIn), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)IvrAudioMixIn_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"An audio file", /*tp_doc*/
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
IvrAudioMixIn_methods, /* tp_methods */
0, /* tp_members */
IvrAudioMixIn_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
IvrAudioMixIn_new, /* tp_new */
};

@ -0,0 +1,20 @@
#ifndef IvrAudioMixIn_h
#define IvrAudioMixIn_h
// Python stuff
#include <Python.h>
#include <structmember.h>
#include "AmAudioMixIn.h"
// Data definition
typedef struct {
PyObject_HEAD
AmAudioMixIn* mix;
} IvrAudioMixIn;
extern PyTypeObject IvrAudioMixInType;
#endif

@ -1,5 +1,7 @@
#include "IvrDialogBase.h"
#include "IvrAudio.h"
#include "IvrAudioMixIn.h"
#
#include "Ivr.h"
#include "IvrSipDialog.h"
@ -183,21 +185,27 @@ static PyObject* IvrDialogBase_enqueue(IvrDialogBase* self, PyObject* args)
assert(self->p_dlg);
PyObject *o_play, *o_rec;
AmAudioFile *a_play=NULL, *a_rec=NULL;
AmAudio *a_play=NULL;
AmAudioFile *a_rec=NULL;
if(!PyArg_ParseTuple(args,"OO",&o_play,&o_rec))
return NULL;
if (o_play != Py_None){
if(!PyObject_TypeCheck(o_play,&IvrAudioFileType)){
if(PyObject_TypeCheck(o_play,&IvrAudioFileType)){
((IvrAudioFile*)o_play)->af->rewind();
a_play = ((IvrAudioFile*)o_play)->af;
} if(PyObject_TypeCheck(o_play,&IvrAudioMixInType)){
a_play = ((IvrAudioMixIn*)o_play)->mix;
} else {
PyErr_SetString(PyExc_TypeError,"Argument 1 is no IvrAudioFile");
return NULL;
}
a_play = ((IvrAudioFile*)o_play)->af;
a_play->rewind();
}
if (o_rec != Py_None){

Loading…
Cancel
Save