[Freeswitch-branches] [commit] r3585 - in freeswitch/branches/jkr888/trunk: scripts src/mod/languages/mod_python
Freeswitch SVN
jkr888 at freeswitch.org
Fri Dec 8 17:11:19 EST 2006
Author: jkr888
Date: Fri Dec 8 17:11:16 2006
New Revision: 3585
Modified:
freeswitch/branches/jkr888/trunk/scripts/mytest.py
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
Log:
Modified: freeswitch/branches/jkr888/trunk/scripts/mytest.py
==============================================================================
--- freeswitch/branches/jkr888/trunk/scripts/mytest.py (original)
+++ freeswitch/branches/jkr888/trunk/scripts/mytest.py Fri Dec 8 17:11:16 2006
@@ -1,6 +1,15 @@
import sys, time
from freeswitch import *
+loop = 1
+
+def DTMFscanner(input, itype, buf, buflen):
+ print "input=",input
+ print "itype=",itype
+ print "buf=",buf
+ print "buflen",buflen
+ return 0
+
print "Hello World"
print sys.path
print dir()
@@ -16,11 +25,14 @@
newSession.console_clean_log("My uuid is " + uuid + "\n")
newSession.answer()
+newSession.set_dtmf_callback(DTMFscanner)
+newSession.set_tts_parms("cepstral", "david")
#fs_switch_ivr_session_transfer(session, "1234", "XML", "default")
newSession.play_file("/root/test.gsm", "")
#fs_switch_ivr_speak_text2(session, "cepstral", "david", "<break time='1s' />Welcome to my first python scripts running from <emphasis level='strong'>free switch </emphasis>application.")
+newSession.speak_text("The first of Europe's gamers got their hands on Nintendo's new video-game console on Friday after stores across the continent opened their doors at midnight to end die-hard fans long wait for a Wii.")
#fs_switch_ivr_speak_text(session,
# "cepstral",
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py Fri Dec 8 17:11:16 2006
@@ -63,6 +63,8 @@
def set_state(*args): return _freeswitch.SessionContainer_set_state(*args)
def play_file(*args): return _freeswitch.SessionContainer_play_file(*args)
def set_dtmf_callback(*args): return _freeswitch.SessionContainer_set_dtmf_callback(*args)
+ def speak_text(*args): return _freeswitch.SessionContainer_speak_text(*args)
+ def set_tts_parms(*args): return _freeswitch.SessionContainer_set_tts_parms(*args)
class SessionContainerPtr(SessionContainer):
def __init__(self, this):
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp Fri Dec 8 17:11:16 2006
@@ -1,9 +1,13 @@
#include "freeswitch_python.h"
+void *globalDTMFCallbackFunction;
+
SessionContainer::SessionContainer(char *nuuid)
{
uuid = nuuid;
dtmfCallbackFunction = NULL;
+ tts_name = NULL;
+ voice_name = NULL;
if ((session = switch_core_session_locate(uuid))) {
switch_core_session_rwunlock(session);
channel = switch_core_session_get_channel(session);
@@ -74,7 +78,7 @@
status = switch_ivr_play_file(session, NULL, file, timer_name, NULL, NULL, 0);
}
else {
- globalDTMFCallBackFunction = dtmfCallbackFunction;
+ globalDTMFCallbackFunction = dtmfCallbackFunction;
status = switch_ivr_play_file(session, NULL, file, timer_name, PythonDTMFCallback, NULL, 0);
}
@@ -93,3 +97,23 @@
}
}
+int SessionContainer::speak_text(char *text)
+{
+ switch_status_t status;
+
+ if (!dtmfCallbackFunction) {
+ status = switch_ivr_speak_text(session, tts_name, voice_name, NULL, 0, NULL, text, NULL, 0);
+ }
+ else {
+ globalDTMFCallbackFunction = dtmfCallbackFunction;
+ status = switch_ivr_speak_text(session, tts_name, voice_name, NULL, 0, PythonDTMFCallback, text, NULL, 0);
+ }
+
+ return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+}
+
+void SessionContainer::set_tts_parms(char *tts_name_p, char *voice_name_p)
+{
+ tts_name = tts_name_p;
+ voice_name = voice_name_p;
+}
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h Fri Dec 8 17:11:16 2006
@@ -1,3 +1,6 @@
+#ifndef FREESWITCH_PYTHON_H
+#define FREESWITCH_PYTHON_H
+
#include <Python.h>
#ifdef __cplusplus
@@ -6,7 +9,7 @@
#include <switch.h>
-extern void *globalDTMFCallBackFunction = NULL;
+extern void *globalDTMFCallbackFunction;
extern switch_status_t PythonDTMFCallback(switch_core_session *session,
void *input,
switch_input_type_t itype,
@@ -19,6 +22,8 @@
switch_channel_t *channel;
char *uuid;
PyObject *dtmfCallbackFunction;
+ char *tts_name;
+ char *voice_name;
public:
SessionContainer(char *uuid);
~SessionContainer();
@@ -32,6 +37,8 @@
void set_state(char *state);
int play_file(char *file, char *timer_name);
void set_dtmf_callback(PyObject *pyfunc);
+ int speak_text(char *text);
+ void set_tts_parms(char *tts_name, char *voice_name);
protected:
};
@@ -39,3 +46,4 @@
}
#endif
+#endif
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i Fri Dec 8 17:11:16 2006
@@ -7,7 +7,7 @@
%{
-extern switch_status_t PythonDTMFCallback(switch_core_session_t *session,
+switch_status_t PythonDTMFCallback(switch_core_session_t *session,
void *input,
switch_input_type_t itype,
void *buf,
@@ -17,7 +17,7 @@
PyObject *result;
switch_status_t dres = SWITCH_STATUS_FALSE;
- func = (PyObject *) globalDTMFCallBackFunction; // Get Python function
+ func = (PyObject *) globalDTMFCallbackFunction; // Get Python function
arglist = Py_BuildValue("(sisi)",input,itype,buf,buflen); // Build argument list
result = PyEval_CallObject(func,arglist); // Call Python
Py_DECREF(arglist); // Trash arglist
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp Fri Dec 8 17:11:16 2006
@@ -1605,7 +1605,7 @@
-extern switch_status_t PythonDTMFCallback(switch_core_session_t *session,
+switch_status_t PythonDTMFCallback(switch_core_session_t *session,
void *input,
switch_input_type_t itype,
void *buf,
@@ -1615,7 +1615,7 @@
PyObject *result;
switch_status_t dres = SWITCH_STATUS_FALSE;
- func = (PyObject *) globalDTMFCallBackFunction; // Get Python function
+ func = (PyObject *) globalDTMFCallbackFunction; // Get Python function
arglist = Py_BuildValue("(sisi)",input,itype,buf,buflen); // Build argument list
result = PyEval_CallObject(func,arglist); // Call Python
Py_DECREF(arglist); // Trash arglist
@@ -1630,24 +1630,24 @@
#ifdef __cplusplus
extern "C" {
#endif
-static int _wrap_globalDTMFCallBackFunction_set(PyObject *_val) {
+static int _wrap_globalDTMFCallbackFunction_set(PyObject *_val) {
{
void * temp;
if ((SWIG_ConvertPtr(_val, static_cast<void ** >(&temp), 0,
SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
- SWIG_append_errmsg("C/C++ variable 'globalDTMFCallBackFunction'");
+ SWIG_append_errmsg("C/C++ variable 'globalDTMFCallbackFunction'");
return 1;
}
- globalDTMFCallBackFunction = (void *) temp;
+ globalDTMFCallbackFunction = (void *) temp;
}
return 0;
}
-static PyObject *_wrap_globalDTMFCallBackFunction_get(void) {
+static PyObject *_wrap_globalDTMFCallbackFunction_get(void) {
PyObject *pyobj = NULL;
- pyobj = SWIG_NewPointerObj((void *)(globalDTMFCallBackFunction), SWIGTYPE_p_void, 0);
+ pyobj = SWIG_NewPointerObj((void *)(globalDTMFCallbackFunction), SWIGTYPE_p_void, 0);
return pyobj;
}
@@ -1973,6 +1973,58 @@
}
+static PyObject *_wrap_SessionContainer_speak_text(PyObject *, PyObject *args) {
+ PyObject *resultobj = NULL;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *arg2 = (char *) 0 ;
+ int result;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"OO:SessionContainer_speak_text",&obj0,&obj1)) goto fail;
+ SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_SessionContainer, SWIG_POINTER_EXCEPTION | 0);
+ if (SWIG_arg_fail(1)) SWIG_fail;
+ if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
+ SWIG_arg_fail(2);SWIG_fail;
+ }
+ result = (int)(arg1)->speak_text(arg2);
+
+ {
+ resultobj = SWIG_From_int(static_cast<int >(result));
+ }
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
+static PyObject *_wrap_SessionContainer_set_tts_parms(PyObject *, PyObject *args) {
+ PyObject *resultobj = NULL;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *arg2 = (char *) 0 ;
+ char *arg3 = (char *) 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"OOO:SessionContainer_set_tts_parms",&obj0,&obj1,&obj2)) goto fail;
+ SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_SessionContainer, SWIG_POINTER_EXCEPTION | 0);
+ if (SWIG_arg_fail(1)) SWIG_fail;
+ if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
+ SWIG_arg_fail(2);SWIG_fail;
+ }
+ if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
+ SWIG_arg_fail(3);SWIG_fail;
+ }
+ (arg1)->set_tts_parms(arg2,arg3);
+
+ Py_INCREF(Py_None); resultobj = Py_None;
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
static PyObject * SessionContainer_swigregister(PyObject *, PyObject *args) {
PyObject *obj;
if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL;
@@ -1994,6 +2046,8 @@
{ (char *)"SessionContainer_set_state", _wrap_SessionContainer_set_state, METH_VARARGS, NULL},
{ (char *)"SessionContainer_play_file", _wrap_SessionContainer_play_file, METH_VARARGS, NULL},
{ (char *)"SessionContainer_set_dtmf_callback", _wrap_SessionContainer_set_dtmf_callback, METH_VARARGS, NULL},
+ { (char *)"SessionContainer_speak_text", _wrap_SessionContainer_speak_text, METH_VARARGS, NULL},
+ { (char *)"SessionContainer_set_tts_parms", _wrap_SessionContainer_set_tts_parms, METH_VARARGS, NULL},
{ (char *)"SessionContainer_swigregister", SessionContainer_swigregister, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL }
};
@@ -2484,6 +2538,6 @@
SWIG_InstallConstants(d,swig_const_table);
PyDict_SetItemString(d,(char*)"cvar", SWIG_globals);
- SWIG_addvarlink(SWIG_globals,(char*)"globalDTMFCallBackFunction",_wrap_globalDTMFCallBackFunction_get, _wrap_globalDTMFCallBackFunction_set);
+ SWIG_addvarlink(SWIG_globals,(char*)"globalDTMFCallbackFunction",_wrap_globalDTMFCallbackFunction_get, _wrap_globalDTMFCallbackFunction_set);
}
More information about the Freeswitch-branches
mailing list