]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11265 #resolve add detectSpeech and playAndDetectSpeech
authorSeven Du <dujinfang@x-y-t.cn>
Sat, 21 Jul 2018 15:55:24 +0000 (23:55 +0800)
committerMike Jerris <mike@jerris.com>
Mon, 13 Aug 2018 18:59:53 +0000 (18:59 +0000)
src/include/switch_cpp.h
src/mod/languages/mod_java/mod_java.i
src/mod/languages/mod_lua/freeswitch.i
src/mod/languages/mod_lua/my_swigable_cpp.h
src/mod/languages/mod_managed/freeswitch.i
src/mod/languages/mod_managed/switch_platform.i
src/mod/languages/mod_perl/freeswitch.i
src/mod/languages/mod_python/mod_python.i
src/switch_cpp.cpp

index 1e050b28467e5a721e0c5e55892ad3d0f080b19c..21126ea571c175fb0f5f116d7b4834bbc8896648 100644 (file)
@@ -316,6 +316,10 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod
                 SWITCH_DECLARE(char *) read(int min_digits, int max_digits,
                                                                         const char *prompt_audio_file, int timeout, const char *valid_terminators, int digit_timeout = 0);
 
+
+               SWITCH_DECLARE(void) detectSpeech(char *arg0, char *arg1 = NULL, char *arg2 = NULL, char *arg3 = NULL);
+
+
        /** \brief Play a file into channel and collect dtmfs
         *
         * See API docs in switch_ivr.h: switch_play_and_get_digits(..)
@@ -331,6 +335,14 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod
                                                                                                 char *digits_regex, const char *var_name = NULL, int digit_timeout = 0,
                                                                                                 const char *transfer_on_failure = NULL);
 
+
+       /** \brief Play a file and detect speech
+        * See API docs switch_ivr_play_and_detect_speech(...)
+        */
+
+               SWITCH_DECLARE(char *) playAndDetectSpeech(char *file, char *engine, char *grammar);
+
+
        /** \brief Play a file that resides on disk into the channel
         *
         * \param file - the path to the .wav/.mp3 to be played
index 858dac8d083fbe11d0e0d93afdc3cb2e9893b445..d79cc53ce9e1c349a153537d9b37b46ae4acbd54 100644 (file)
@@ -13,6 +13,9 @@
 %newobject CoreSession;
 %newobject Event;
 %newobject Stream;
+%newobject API::execute;
+%newobject API::executeString;
+%newobject CoreSession::playAndDetectSpeech;
 
 
 // I thought we were using swig because it's easier than the alternatives :-)
index 4933bfefbcffe28fd5f14f7e8e603f3299eeae58..8f114fcb8875730b347ce15b209e9449d3dc74de 100644 (file)
@@ -42,6 +42,7 @@
 %newobject Dbh;
 %newobject API::execute;
 %newobject API::executeString;
+%newobject CoreSession::playAndDetectSpeech;
 
 %include "typemaps.i"
 %apply int *OUTPUT { int *len };
index 80f689e56ef891d393d8622df2b00e0d8d8c8e8f..8c0e6233e3092390de61c2a38db907bf31aa6a9d 100644 (file)
@@ -128,6 +128,10 @@ class CoreSession {
                                                 int max_digits,
                                                 int max_tries,
                                                 int timeout, char *terminators, char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
+
+       int playAndDetectSpeech(char *file, char *engine, char *grammar);
+       void detectSpeech(char *arg0, char * = NULL, char *arg2 = NULL, char *arg3 = NULL);
+
        int streamFile(char *file, int starting_sample_count = 0);
 
 
index 1123651479c4bd0395fc887961a0a8a9665671c9..b38300af96795380892453b03b142601a6c19240 100644 (file)
@@ -84,6 +84,7 @@ char * SWIG_csharp_string_callback(const char * str) {
 %newobject Stream;\r
 %newobject API::execute;\r
 %newobject API::executeString;\r
+%newobject CoreSession::playAndDetectSpeech;\r
 \r
 // Allow bitwise compare on flag fields\r
 %typemap(csclassmodifiers) session_flag_t "[System.Flags] public enum"\r
index a6f0aaa6ba459036ad370b8f07a68467df9f512d..fa78438260de73dd9a21257bab753954fa2995f3 100644 (file)
@@ -45,6 +45,9 @@ typedef unsigned long in_addr_t;
 %newobject CoreSession;\r
 %newobject Event;\r
 %newobject Stream;\r
+%newobject API::execute;\r
+%newobject API::executeString;\r
+%newobject CoreSession::playAndDetectSpeech;\r
 \r
 #define SWITCH_DECLARE(type) type\r
 #define SWITCH_DECLARE_NONSTD(type) type\r
index 262a70e2c17d5bfe45c632240659febaefc108b4..2674b01f814bd975b24343f8b93d38b3db2e3a18 100644 (file)
@@ -17,6 +17,7 @@
 %newobject Stream;
 %newobject API::execute;
 %newobject API::executeString;
+%newobject CoreSession::playAndDetectSpeech;
 
 /** insert the following includes into generated code so it compiles */
 %{
index c22acf6055cd3ca3489ca8cab1ea114771b74f0a..0e8be465eea775460abf62a421a714701dcc4313 100644 (file)
@@ -14,6 +14,9 @@
 %newobject CoreSession;
 %newobject Event;
 %newobject Stream;
+%newobject API::execute;
+%newobject API::executeString;
+%newobject CoreSession::playAndDetectSpeech;
 
 /** insert the following includes into generated code so it compiles */
 %{
index 3741ba2ffd9d9546b05e84fbea2bf5c52c5b9323..342d91a1878142c4d02c6477717d0c782be3aaf7 100644 (file)
@@ -984,6 +984,71 @@ SWITCH_DECLARE(char *) CoreSession::playAndGetDigits(int min_digits,
        return dtmf_buf;
 }
 
+SWITCH_DECLARE(void) CoreSession::detectSpeech(char *arg0, char *arg1, char *arg2, char *arg3)
+{
+       this_check_void();
+       sanity_check_noreturn;
+
+       begin_allow_threads();
+
+       if (!arg0) return;
+
+       if (!strcasecmp(arg0, "grammar") && arg1 && arg2) {
+               switch_ivr_detect_speech_load_grammar(session, arg1, arg2);
+       } else if (!strcasecmp(arg0, "nogrammar") && arg1) {
+               switch_ivr_detect_speech_unload_grammar(session, arg1);
+       } else if (!strcasecmp(arg0, "grammaron") && arg1) {
+               switch_ivr_detect_speech_enable_grammar(session, arg1);
+       } else if (!strcasecmp(arg0, "grammaroff") && arg1) {
+               switch_ivr_detect_speech_disable_grammar(session, arg1);
+       } else if (!strcasecmp(arg0, "grammarsalloff")) {
+               switch_ivr_detect_speech_disable_all_grammars(session);
+       } else if (!strcasecmp(arg0, "init") && arg1 && arg2) {
+               switch_ivr_detect_speech_init(session, arg1, arg2, NULL);
+       } else if (!strcasecmp(arg0, "pause")) {
+               switch_ivr_pause_detect_speech(session);
+       } else if (!strcasecmp(arg0, "resume")) {
+               switch_ivr_resume_detect_speech(session);
+       } else if (!strcasecmp(arg0, "stop")) {
+               switch_ivr_stop_detect_speech(session);
+       } else if (!strcasecmp(arg0, "param") && arg1 && arg2) {
+               switch_ivr_set_param_detect_speech(session, arg1, arg2);
+       } else if (!strcasecmp(arg0, "start-input-timers")) {
+               switch_ivr_detect_speech_start_input_timers(session);
+       } else if (!strcasecmp(arg0, "start_input_timers")) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "start_input_timers is deprecated, please use start-input-timers instead!\n");
+               switch_ivr_detect_speech_start_input_timers(session);
+       } else if (arg1 && arg2 && arg3) {
+               switch_ivr_detect_speech(session, arg0, arg1, arg2, arg3, NULL);
+       }
+
+       end_allow_threads();
+}
+
+SWITCH_DECLARE(char *) CoreSession::playAndDetectSpeech(char *file, char *engine, char *grammar)
+{
+       sanity_check((char *)"");
+       this_check((char *)"");
+       begin_allow_threads();
+
+       char *result = NULL;
+
+       switch_status_t status = switch_ivr_play_and_detect_speech(session, file, engine, grammar, &result, 0, NULL);
+       if (status == SWITCH_STATUS_SUCCESS) {
+               // good
+       } else if (status == SWITCH_STATUS_GENERR) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "GRAMMAR ERROR\n");
+       } else if (status == SWITCH_STATUS_NOT_INITALIZED) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "ASR INIT ERROR\n");
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "ERROR\n");
+       }
+
+       end_allow_threads();
+
+       return result; // remeber to free me
+}
+
 SWITCH_DECLARE(void) CoreSession::say(const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender)
 {
        this_check_void();