From acec4777c28cfbbb608ee03d08e1e97e86f7a8c2 Mon Sep 17 00:00:00 2001 From: Brian West Date: Sat, 20 Jun 2009 03:40:46 +0000 Subject: [PATCH] Author: achaloyan Date: Fri Jun 19 19:14:14 2009 +0000 svn-id: https://unimrcp.googlecode.com/svn/trunk@996 f001bc3a-424a-0410-80a0-a715b8f413a8 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13881 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/unimrcp/.update | 2 +- .../build/vsprops/pocketsphinx.vsprops | 25 ++ .../plugins/mrcp-pocketsphinx/Makefile.am | 16 ++ .../mrcp-pocketsphinx/mrcppocketsphinx.vcproj | 165 +++++++++++++ .../mrcp-pocketsphinx/src/mrcp_pocketsphinx.c | 232 ++++++++++++++++++ 5 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 libs/unimrcp/build/vsprops/pocketsphinx.vsprops create mode 100644 libs/unimrcp/plugins/mrcp-pocketsphinx/Makefile.am create mode 100644 libs/unimrcp/plugins/mrcp-pocketsphinx/mrcppocketsphinx.vcproj create mode 100644 libs/unimrcp/plugins/mrcp-pocketsphinx/src/mrcp_pocketsphinx.c diff --git a/libs/unimrcp/.update b/libs/unimrcp/.update index d8ab9c6b2c..943e66d3df 100644 --- a/libs/unimrcp/.update +++ b/libs/unimrcp/.update @@ -1 +1 @@ -Tue Jun 16 17:36:06 CDT 2009 +Fri Jun 19 22:39:34 CDT 2009 diff --git a/libs/unimrcp/build/vsprops/pocketsphinx.vsprops b/libs/unimrcp/build/vsprops/pocketsphinx.vsprops new file mode 100644 index 0000000000..52e284bd8f --- /dev/null +++ b/libs/unimrcp/build/vsprops/pocketsphinx.vsprops @@ -0,0 +1,25 @@ + + + + + + + diff --git a/libs/unimrcp/plugins/mrcp-pocketsphinx/Makefile.am b/libs/unimrcp/plugins/mrcp-pocketsphinx/Makefile.am new file mode 100644 index 0000000000..740df1d2da --- /dev/null +++ b/libs/unimrcp/plugins/mrcp-pocketsphinx/Makefile.am @@ -0,0 +1,16 @@ +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -Iinclude \ + -I$(top_srcdir)/libs/mrcp-engine/include \ + -I$(top_srcdir)/libs/mrcp/include \ + -I$(top_srcdir)/libs/mrcp/message/include \ + -I$(top_srcdir)/libs/mrcp/control/include \ + -I$(top_srcdir)/libs/mrcp/resources/include \ + -I$(top_srcdir)/libs/mpf/include \ + -I$(top_srcdir)/libs/apr-toolkit/include \ + $(UNIMRCP_APR_INCLUDES) $(UNIMRCP_APU_INCLUDES) + +plugin_LTLIBRARIES = mrcppocketsphinx.la + +mrcppocketsphinx_la_SOURCES = src/mrcp_pocketsphinx.c.c +mrcppocketsphinx_la_LDFLAGS = -module $(PLUGIN_LT_VERSION) diff --git a/libs/unimrcp/plugins/mrcp-pocketsphinx/mrcppocketsphinx.vcproj b/libs/unimrcp/plugins/mrcp-pocketsphinx/mrcppocketsphinx.vcproj new file mode 100644 index 0000000000..c04f99707f --- /dev/null +++ b/libs/unimrcp/plugins/mrcp-pocketsphinx/mrcppocketsphinx.vcproj @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/unimrcp/plugins/mrcp-pocketsphinx/src/mrcp_pocketsphinx.c b/libs/unimrcp/plugins/mrcp-pocketsphinx/src/mrcp_pocketsphinx.c new file mode 100644 index 0000000000..4452143188 --- /dev/null +++ b/libs/unimrcp/plugins/mrcp-pocketsphinx/src/mrcp_pocketsphinx.c @@ -0,0 +1,232 @@ +/* + * Copyright 2008 Arsen Chaloyan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Some mandatory rules for plugin implementation. + * 1. Each plugin MUST contain the following function as an entry point of the plugin + * MRCP_PLUGIN_DECLARE(mrcp_resource_engine_t*) mrcp_plugin_create(apr_pool_t *pool) + * 2. One and only one response MUST be sent back to the received request. + * 3. Methods (callbacks) of the MRCP engine channel MUST not block. + * (asynch response can be sent from the context of other thread) + * 4. Methods (callbacks) of the MPF engine stream MUST not block. + */ + +#include "mrcp_resource_engine.h" +#include "mrcp_recog_resource.h" +#include "mrcp_recog_header.h" +#include "mrcp_generic_header.h" +#include "mrcp_message.h" +#include "mpf_activity_detector.h" +#include "apt_log.h" + + +typedef struct pocketsphinx_engine_t pocketsphinx_engine_t; +typedef struct pocketsphinx_recognizer_t pocketsphinx_recognizer_t; + +/** Declaration of recognizer engine methods */ +static apt_bool_t pocketsphinx_engine_destroy(mrcp_resource_engine_t *engine); +static apt_bool_t pocketsphinx_engine_open(mrcp_resource_engine_t *engine); +static apt_bool_t pocketsphinx_engine_close(mrcp_resource_engine_t *engine); +static mrcp_engine_channel_t* pocketsphinx_recognizer_create(mrcp_resource_engine_t *engine, apr_pool_t *pool); + +static const struct mrcp_engine_method_vtable_t engine_vtable = { + pocketsphinx_engine_destroy, + pocketsphinx_engine_open, + pocketsphinx_engine_close, + pocketsphinx_recognizer_create +}; + + +/** Declaration of recognizer channel methods */ +static apt_bool_t pocketsphinx_recognizer_destroy(mrcp_engine_channel_t *channel); +static apt_bool_t pocketsphinx_recognizer_open(mrcp_engine_channel_t *channel); +static apt_bool_t pocketsphinx_recognizer_close(mrcp_engine_channel_t *channel); +static apt_bool_t pocketsphinx_recognizer_request_process(mrcp_engine_channel_t *channel, mrcp_message_t *request); + +static const struct mrcp_engine_channel_method_vtable_t channel_vtable = { + pocketsphinx_recognizer_destroy, + pocketsphinx_recognizer_open, + pocketsphinx_recognizer_close, + pocketsphinx_recognizer_request_process +}; + +/** Declaration of recognizer audio stream methods */ +static apt_bool_t pocketsphinx_stream_destroy(mpf_audio_stream_t *stream); +static apt_bool_t pocketsphinx_stream_open(mpf_audio_stream_t *stream); +static apt_bool_t pocketsphinx_stream_close(mpf_audio_stream_t *stream); +static apt_bool_t pocketsphinx_stream_write(mpf_audio_stream_t *stream, const mpf_frame_t *frame); + +static const mpf_audio_stream_vtable_t audio_stream_vtable = { + pocketsphinx_stream_destroy, + NULL, + NULL, + NULL, + pocketsphinx_stream_open, + pocketsphinx_stream_close, + pocketsphinx_stream_write +}; + +/** Declaration of pocketsphinx engine */ +struct pocketsphinx_engine_t { + mrcp_resource_engine_t *base; +}; + +/** Declaration of pocketsphinx recognizer */ +struct pocketsphinx_recognizer_t { + /** Back pointer to engine */ + pocketsphinx_engine_t *engine; + /** Engine channel base */ + mrcp_engine_channel_t *channel; +}; + +/** Declare this macro to use log routine of the server, plugin is loaded from */ +MRCP_PLUGIN_LOGGER_IMPLEMENT + + +/** Create pocketsphinx engine (engine is an aggregation of recognizers) */ +MRCP_PLUGIN_DECLARE(mrcp_resource_engine_t*) mrcp_plugin_create(apr_pool_t *pool) +{ + pocketsphinx_engine_t *engine = apr_palloc(pool,sizeof(pocketsphinx_engine_t)); + + /* create resource engine base */ + engine->base = mrcp_resource_engine_create( + MRCP_RECOGNIZER_RESOURCE, /* MRCP resource identifier */ + engine, /* object to associate */ + &engine_vtable, /* virtual methods table of resource engine */ + pool); /* pool to allocate memory from */ + return engine->base; +} + +static apt_bool_t pocketsphinx_engine_destroy(mrcp_resource_engine_t *engine) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_engine_open(mrcp_resource_engine_t *engine) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_engine_close(mrcp_resource_engine_t *engine) +{ + return TRUE; +} + +/** Create pocketsphinx recognizer */ +static mrcp_engine_channel_t* pocketsphinx_recognizer_create(mrcp_resource_engine_t *engine, apr_pool_t *pool) +{ + mrcp_engine_channel_t *channel; + pocketsphinx_recognizer_t *recognizer = apr_palloc(pool,sizeof(pocketsphinx_recognizer_t)); + + /* create engine channel base */ + channel = mrcp_engine_sink_channel_create( + engine, /* resource engine */ + &channel_vtable, /* virtual methods table of engine channel */ + &audio_stream_vtable, /* virtual methods table of audio stream */ + recognizer, /* object to associate */ + NULL, /* codec descriptor might be NULL by default */ + pool); /* pool to allocate memory from */ + + recognizer->channel = channel; + return channel; +} + +/** Destroy engine channel */ +static apt_bool_t pocketsphinx_recognizer_destroy(mrcp_engine_channel_t *channel) +{ + return TRUE; +} + +/** Open engine channel (asynchronous response MUST be sent)*/ +static apt_bool_t pocketsphinx_recognizer_open(mrcp_engine_channel_t *channel) +{ + return mrcp_engine_channel_open_respond(channel,TRUE); +} + +/** Close engine channel (asynchronous response MUST be sent)*/ +static apt_bool_t pocketsphinx_recognizer_close(mrcp_engine_channel_t *channel) +{ + return mrcp_engine_channel_close_respond(channel); +} + + +/** Process RECOGNIZE request */ +static apt_bool_t pocketsphinx_recognize(pocketsphinx_recognizer_t *recognizer, mrcp_message_t *request, mrcp_message_t *response) +{ + return TRUE; +} + +/** Process STOP request */ +static apt_bool_t pocketsphinx_stop(pocketsphinx_recognizer_t *recognizer, mrcp_message_t *request, mrcp_message_t *response) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_recognizer_request_process(mrcp_engine_channel_t *channel, mrcp_message_t *request) +{ + pocketsphinx_recognizer_t *recognizer = channel->method_obj; + apt_bool_t processed = FALSE; + mrcp_message_t *response = mrcp_response_create(request,request->pool); + switch(request->start_line.method_id) { + case RECOGNIZER_SET_PARAMS: + break; + case RECOGNIZER_GET_PARAMS: + break; + case RECOGNIZER_DEFINE_GRAMMAR: + break; + case RECOGNIZER_RECOGNIZE: + processed = pocketsphinx_recognize(recognizer,request,response); + break; + case RECOGNIZER_GET_RESULT: + break; + case RECOGNIZER_START_INPUT_TIMERS: + break; + case RECOGNIZER_STOP: + processed = pocketsphinx_stop(recognizer,request,response); + break; + default: + break; + } + if(processed == FALSE) { + /* send asynchronous response for not handled request */ + mrcp_engine_channel_message_send(channel,response); + } + return TRUE; +} + + + + + +static apt_bool_t pocketsphinx_stream_destroy(mpf_audio_stream_t *stream) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_stream_open(mpf_audio_stream_t *stream) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_stream_close(mpf_audio_stream_t *stream) +{ + return TRUE; +} + +static apt_bool_t pocketsphinx_stream_write(mpf_audio_stream_t *stream, const mpf_frame_t *frame) +{ + return TRUE; +}