### Install asrclient Executable and Debug Symbols Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Defines installation rules for the asrclient executable, placing it in the 'bin' directory. For MSVC builds, it also installs PDB files for debugging. ```cmake install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) if (MSVC) install (FILES ${PROJECT_BINARY_DIR}/Debug/${PROJECT_OUTPUT_NAME}.pdb DESTINATION bin CONFIGURATIONS Debug) install (FILES ${PROJECT_BINARY_DIR}/RelWithDebInfo/${PROJECT_OUTPUT_NAME}.pdb DESTINATION bin CONFIGURATIONS RelWithDebInfo) endif (MSVC) ``` -------------------------------- ### CMakeLists.txt Project Setup Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Initializes the CMake build system for the mpftest project with a minimum required version. ```cmake cmake_minimum_required (VERSION 2.8) project (mpftest) ``` -------------------------------- ### Start UniMRCP Server Source: https://context7.com/unispeech/unimrcp/llms.txt Initializes and starts the UniMRCP server using a specified directory layout configuration. Ensure APR is initialized before calling. ```c #include "unimrcp_server.h" #include "apt_dir_layout.h" #include "apt_pool.h" int main(int argc, char *argv[]) { apr_pool_t *pool; apt_dir_layout_t *dir_layout; mrcp_server_t *server; /* Initialize APR */ apr_initialize(); pool = apt_pool_create(); /* Create default directory layout (/usr/local/unimrcp) */ dir_layout = apt_default_dir_layout_create("/usr/local/unimrcp", pool); /* Start the MRCP server */ server = unimrcp_server_start(dir_layout); if (!server) { printf("Failed to start UniMRCP server\n"); return 1; } printf("UniMRCP server started successfully\n"); /* Run server (wait for termination signal) */ /* ... application logic ... */ /* Shutdown server gracefully */ unimrcp_server_shutdown(server); apr_pool_destroy(pool); apr_terminate(); return 0; } ``` -------------------------------- ### CMake Build Configuration for demosynth Source: https://github.com/unispeech/unimrcp/blob/master/plugins/demo-synth/CMakeLists.txt Defines the project, source files, library dependencies, and installation paths for the UniMRCP demo synth plugin. ```cmake cmake_minimum_required (VERSION 2.8) project (demosynth) # Set source files set (DEMO_SYNTH_SOURCES src/demo_synth_engine.c ) source_group ("src" FILES ${DEMO_SYNTH_SOURCES}) # Plug-in declaration add_library (${PROJECT_NAME} MODULE ${DEMO_SYNTH_SOURCES} $ $ $ $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "plugins") # Input libraries target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () # Preprocessor definitions add_definitions ( ${MRCP_DEFINES} ${MPF_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${MRCP_ENGINE_INCLUDE_DIRS} ${MRCP_INCLUDE_DIRS} ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) # Installation directives install (TARGETS ${PROJECT_NAME} LIBRARY DESTINATION plugin) if (MSVC) install (FILES ${PROJECT_BINARY_DIR}/Debug/${PROJECT_NAME}.pdb DESTINATION plugin CONFIGURATIONS Debug) install (FILES ${PROJECT_BINARY_DIR}/RelWithDebInfo/${PROJECT_NAME}.pdb DESTINATION plugin CONFIGURATIONS RelWithDebInfo) endif (MSVC) ``` -------------------------------- ### Configure UniMRCP Plugin Build Source: https://github.com/unispeech/unimrcp/blob/master/plugins/demo-recog/CMakeLists.txt This CMake script sets up the build environment for a UniMRCP plugin. It defines source files, links necessary libraries, and configures installation paths. ```cmake cmake_minimum_required (VERSION 2.8) project (demorecog) # Set source files set (DEMO_RECOG_SOURCES src/demo_recog_engine.c ) source_group ("src" FILES ${DEMO_RECOG_SOURCES}) # Plug-in declaration add_library (${PROJECT_NAME} MODULE ${DEMO_RECOG_SOURCES} $ $ $ $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "plugins") # Input libraries target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () # Preprocessor definitions add_definitions ( ${MRCP_DEFINES} ${MPF_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${MRCP_ENGINE_INCLUDE_DIRS} ${MRCP_INCLUDE_DIRS} ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) # Installation directives install (TARGETS ${PROJECT_NAME} LIBRARY DESTINATION plugin) if (MSVC) install (FILES ${PROJECT_BINARY_DIR}/Debug/${PROJECT_NAME}.pdb DESTINATION plugin CONFIGURATIONS Debug) install (FILES ${PROJECT_BINARY_DIR}/RelWithDebInfo/${PROJECT_NAME}.pdb DESTINATION plugin CONFIGURATIONS RelWithDebInfo) endif (MSVC) ``` -------------------------------- ### Configure CMake Project for asrclient Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Sets the minimum CMake version and project name for the asrclient application. This is a standard CMake setup. ```cmake cmake_minimum_required (VERSION 2.8) project (asrclient-app) ``` -------------------------------- ### UniMRCP Server CMake Configuration Source: https://github.com/unispeech/unimrcp/blob/master/platforms/unimrcp-server/CMakeLists.txt Defines the build process for the UniMRCP server application using CMake. Includes setting project name, source files, executable target, library linking, preprocessor definitions, include paths, and installation rules. ```cmake cmake_minimum_required (VERSION 2.8) project (unimrcpserver-app) set (PROJECT_OUTPUT_NAME unimrcpserver) # Set source files set (UNIMRCP_SERVER_SOURCES src/main.c src/uni_cmdline.c src/uni_daemon.c ) if (WIN32) set (UNIMRCP_SERVER_SOURCES ${UNIMRCP_SERVER_SOURCES} src/uni_service.c) endif (WIN32) source_group ("src" FILES ${UNIMRCP_SERVER_SOURCES}) # Application declaration add_executable (${PROJECT_NAME} ${UNIMRCP_SERVER_SOURCES}) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "platforms") set_target_properties (${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_OUTPUT_NAME}) # Input libraries target_link_libraries(${PROJECT_NAME} unimrcpserver) # Preprocessor definitions add_definitions ( ${MRCP_DEFINES} ${MPF_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${VERSION_INCLUDE_DIRS} ${UNIMRCP_SERVER_INCLUDE_DIRS} ${MRCP_SERVER_INCLUDE_DIRS} ${MRCP_ENGINE_INCLUDE_DIRS} ${MRCP_SIGNALING_INCLUDE_DIRS} ${MRCPv2_TRANSPORT_INCLUDE_DIRS} ${MRCP_INCLUDE_DIRS} ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) # Installation directives install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) if (MSVC) install (FILES ${PROJECT_BINARY_DIR}/Debug/${PROJECT_OUTPUT_NAME}.pdb DESTINATION bin CONFIGURATIONS Debug) install (FILES ${PROJECT_BINARY_DIR}/RelWithDebInfo/${PROJECT_OUTPUT_NAME}.pdb DESTINATION bin CONFIGURATIONS RelWithDebInfo) endif (MSVC) ``` -------------------------------- ### Handle MRCP Events Source: https://context7.com/unispeech/unimrcp/llms.txt Processes incoming MRCP events such as recognition completion, start of input, and synthesizer completion. Requires inclusion of mrcp_application.h and relevant resource headers. ```c #include "mrcp_application.h" #include "mrcp_recog_header.h" #include "mrcp_synth_header.h" #include "apt_nlsml_doc.h" static apt_bool_t on_message_receive(mrcp_application_t *app, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message) { /* Check if it's an event */ if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) { /* Handle recognizer events */ if (message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) { mrcp_recog_header_t *recog_header; recog_header = mrcp_resource_header_get(message); if (recog_header) { printf("Recognition complete, cause: %d\n", recog_header->completion_cause); if (recog_header->completion_cause == RECOGNIZER_COMPLETION_CAUSE_SUCCESS) { /* Parse NLSML result */ if (message->body.length > 0) { printf("Result: %.*s\n", (int)message->body.length, message->body.buf); } } } } else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) { printf("Speech detected - START-OF-INPUT event\n"); } /* Handle synthesizer events */ else if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) { mrcp_synth_header_t *synth_header; synth_header = mrcp_resource_header_get(message); if (synth_header) { printf("Speak complete, cause: %d\n", synth_header->completion_cause); } } } return TRUE; } ``` -------------------------------- ### Creating a Custom Engine Channel Source: https://context7.com/unispeech/unimrcp/llms.txt Demonstrates the creation of a new engine channel, including setting up media stream capabilities and associating it with the engine. This function is typically called during engine initialization. ```c /* Called from my_engine_channel_create */ mrcp_engine_channel_t* create_my_channel(mrcp_engine_t *engine, apr_pool_t *pool) { my_channel_t *my_channel; mpf_stream_capabilities_t *caps; mpf_termination_t *termination; my_channel = apr_palloc(pool, sizeof(my_channel_t)); my_channel->recog_request = NULL; my_channel->timers_started = FALSE; /* Create stream capabilities */ caps = mpf_sink_stream_capabilities_create(pool); mpf_codec_capabilities_add(&caps->codecs, MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000, "LPCM"); /* Create media termination */ termination = mrcp_engine_audio_termination_create( my_channel, NULL, /* audio stream vtable */ caps, pool ); /* Create engine channel */ my_channel->channel = mrcp_engine_channel_create( engine, &channel_vtable, my_channel, termination, pool ); return my_channel->channel; } ``` -------------------------------- ### Build UniMRCP from Source Source: https://context7.com/unispeech/unimrcp/llms.txt Standard sequence for compiling UniMRCP on Unix-like systems. Requires the GNU build system tools and appropriate development headers for dependencies. ```bash # Bootstrap (if building from repository) ./bootstrap # Configure with default paths ./configure # Configure with custom library paths ./configure \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr \ --with-sofia-sip=/usr/local/sofia-sip # Build for 64-bit CFLAGS=-m64 CXXFLAGS=-m64 LDFLAGS=-m64 ./configure # Compile make # Install (default: /usr/local/unimrcp) sudo make install # Install default configuration cd conf && make def-conf # Install default data files cd data && make def-data ``` -------------------------------- ### Create MRCP Sessions Source: https://context7.com/unispeech/unimrcp/llms.txt Demonstrates creating an MRCP session using a profile configuration, with options for standard creation or using an external memory pool. ```c #include "mrcp_application.h" /* Create a new MRCP session for speech recognition */ mrcp_session_t* create_recog_session(mrcp_application_t *app, void *user_data) { mrcp_session_t *session; /* Create session using the "uni2" profile (MRCPv2) */ session = mrcp_application_session_create(app, "uni2", user_data); if (!session) { printf("Failed to create MRCP session\n"); return NULL; } /* Set optional session name for debugging */ mrcp_application_session_name_set(session, "ASR-Session-001"); printf("Created MRCP session: %s\n", mrcp_application_session_id_get(session)->buf); return session; } /* Create session with custom memory pool */ mrcp_session_t* create_session_with_pool(mrcp_application_t *app, apr_pool_t *external_pool) { return mrcp_application_session_create_ex( app, "uni2", /* profile name */ NULL, /* user data */ TRUE, /* take ownership of pool */ external_pool /* external memory pool */ ); } ``` -------------------------------- ### Create MRCP Control Channels Source: https://context7.com/unispeech/unimrcp/llms.txt Shows how to define audio stream callbacks and create a recognizer channel associated with a session. ```c #include "mrcp_application.h" #include "mrcp_recog_resource.h" /* Audio stream callbacks for recognition */ static apt_bool_t stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame) { /* Read audio frames from source (e.g., file, microphone) */ FILE *audio_file = stream->obj; if (audio_file) { size_t bytes_read = fread(frame->codec_frame.buffer, 1, frame->codec_frame.size, audio_file); if (bytes_read == frame->codec_frame.size) { frame->type |= MEDIA_FRAME_TYPE_AUDIO; } } return TRUE; } static const mpf_audio_stream_vtable_t stream_vtable = { NULL, /* destroy */ NULL, /* open */ NULL, /* close */ stream_read, /* read */ NULL, /* write */ NULL, NULL, NULL }; mrcp_channel_t* create_recognizer_channel(mrcp_session_t *session, FILE *audio_file) { mpf_termination_t *termination; mpf_stream_capabilities_t *caps; mrcp_channel_t *channel; apr_pool_t *pool = mrcp_application_session_pool_get(session); /* Create stream capabilities */ caps = mpf_source_stream_capabilities_create(pool); mpf_codec_capabilities_add(&caps->codecs, MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000, "LPCM"); /* Create audio termination */ termination = mrcp_application_audio_termination_create( session, &stream_vtable, caps, audio_file /* object passed to stream callbacks */ ); /* Create recognizer channel */ channel = mrcp_application_channel_create( session, MRCP_RECOGNIZER_RESOURCE, /* resource type */ termination, NULL, /* RTP descriptor (NULL for default) */ NULL /* user data */ ); return channel; } ``` -------------------------------- ### Configure UniMRCP Server XML Source: https://context7.com/unispeech/unimrcp/llms.txt Defines server properties, signaling agents, media engines, and plugin factories. Ensure all referenced IDs in the profiles section match the components defined in the components block. ```xml 8060 udp,tcp UniMRCP Server UniMRCPServer 600 1554 100 1544 100 false 1 5000 6000 50 1 50 600 20 PCMU PCMA G722 L16/96/8000 SIP-Agent-1 MRCPv2-Agent-1 Media-Engine-1 RTP-Factory-1 RTP-Settings-1 RTSP-Agent-1 Media-Engine-1 RTP-Factory-1 RTP-Settings-1 ``` -------------------------------- ### Build RTSP Test Executable with CMake Source: https://github.com/unispeech/unimrcp/blob/master/tests/rtsptest/CMakeLists.txt Configures the build process for the RTSP test application. Links against necessary libraries and sets include directories and preprocessor definitions. ```cmake cmake_minimum_required (VERSION 2.8) project (rtsptest) # Set source files set (RTSP_TEST_SOURCES src/main.c src/parse_gen_suite.c ) source_group ("src" FILES ${RTSP_TEST_SOURCES}) # Application declaration add_executable (${PROJECT_NAME} ${RTSP_TEST_SOURCES} $ $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "tests") # Input libraries target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () # Preprocessor definitions add_definitions ( ${RTSP_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${RTSP_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Create and Destroy ASR Engine Source: https://context7.com/unispeech/unimrcp/llms.txt Initializes the ASR engine with specified root directory and logging parameters. Ensure the engine is destroyed after use to prevent memory leaks. ```c #include "asr_engine.h" asr_engine_t* create_asr_engine(void) { asr_engine_t *engine; /* Create ASR engine with default settings */ engine = asr_engine_create( "/usr/local/unimrcp", /* root directory */ APT_PRIO_INFO, /* log priority (0-7) */ APT_LOG_OUTPUT_CONSOLE /* log output mode */ ); if (!engine) { printf("Failed to create ASR engine\n"); return NULL; } printf("ASR engine created successfully\n"); return engine; } void destroy_asr_engine(asr_engine_t *engine) { asr_engine_destroy(engine); } ``` -------------------------------- ### UniMRCP CMake Build Configuration Source: https://github.com/unispeech/unimrcp/blob/master/tests/mrcptest/CMakeLists.txt This snippet defines the main build configuration for the UniMRCP project using CMake. It sets up the project, identifies source files, creates an executable target, links necessary libraries, and defines preprocessor macros and include paths. ```cmake cmake_minimum_required (VERSION 2.8) project (mrcptest) # Set source files set (MRCP_TEST_SOURCES src/main.c src/parse_gen_suite.c src/set_get_suite.c src/transparent_set_get_suite.c ) source_group ("src" FILES ${MRCP_TEST_SOURCES}) # Application declaration add_executable (${PROJECT_NAME} ${MRCP_TEST_SOURCES} $ $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "tests") # Input libraries target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () # Preprocessor definitions add_definitions ( ${MRCP_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${MRCP_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Perform Real-Time Speech Recognition with Audio Streaming Source: https://context7.com/unispeech/unimrcp/llms.txt Initiates stream-based recognition and simulates writing audio data to the recognition stream. Ensure audio is paced to real-time for optimal performance. ```c #include "asr_engine.h" void recognize_from_stream(asr_engine_t *engine, const char *grammar_file) { asr_session_t *session; const char *result; char audio_buffer[320]; /* 20ms of 8kHz 16-bit audio */ FILE *audio_source; session = asr_session_create(engine, "uni2"); if (!session) { return; } /* Start stream-based recognition */ /* This sends RECOGNIZE request and waits for audio */ result = asr_session_stream_recognize(session, grammar_file); /* Simulate audio streaming from a source */ audio_source = fopen("/path/to/audio.pcm", "rb"); if (audio_source) { while (fread(audio_buffer, 1, sizeof(audio_buffer), audio_source) > 0) { /* Write audio data to the recognition stream */ asr_session_stream_write(session, audio_buffer, sizeof(audio_buffer)); /* In real application, pace this to real-time */ /* usleep(20000); */ /* 20ms delay */ } fclose(audio_source); } /* Result will be available after end-of-speech detection */ if (result) { printf("Stream recognition result: %s\n", result); } asr_session_destroy(session); } ``` -------------------------------- ### Configure Include Directories Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Specifies the directories where the compiler should look for header files during the build process. ```cmake include_directories ( ${PROJECT_SOURCE_DIR}/include ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Configure unirtsp library with CMake Source: https://github.com/unispeech/unimrcp/blob/master/libs/uni-rtsp/CMakeLists.txt Defines the project structure, source files, and build dependencies for the unirtsp library. ```cmake cmake_minimum_required (VERSION 2.8) project (unirtsp) # Set header files set (UNIRTSP_HEADERS include/rtsp.h include/rtsp_header.h include/rtsp_start_line.h include/rtsp_message.h include/rtsp_stream.h include/rtsp_server.h include/rtsp_client.h ) source_group ("include" FILES ${UNIRTSP_HEADERS}) # Set source files set (UNIRTSP_SOURCES src/rtsp_header.c src/rtsp_start_line.c src/rtsp_message.c src/rtsp_stream.c src/rtsp_server.c src/rtsp_client.c ) source_group ("src" FILES ${UNIRTSP_SOURCES}) # Library declaration add_library (${PROJECT_NAME} OBJECT ${UNIRTSP_SOURCES} ${UNIRTSP_HEADERS}) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "libs") # Preprocessor definitions add_definitions ( ${RTSP_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Define Source Files for Test Application Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Specifies the source files for the mpftest executable and groups them under a 'src' directory in the build. ```cmake set (MPF_TEST_SOURCES src/main.c src/mpf_suite.c ) source_group ("src" FILES ${MPF_TEST_SOURCES}) ``` -------------------------------- ### Creating an MRCP Session Source: https://context7.com/unispeech/unimrcp/llms.txt Demonstrates how to create a new MRCP session using `mrcp_application_session_create()` and `mrcp_application_session_create_ex()` for custom memory pool allocation. ```APIDOC ## Creating an MRCP Session The `mrcp_application_session_create()` function creates a new MRCP session using the specified profile configuration. ```c #include "mrcp_application.h" /* Create a new MRCP session for speech recognition */ mrcp_session_t* create_recog_session(mrcp_application_t *app, void *user_data) { mrcp_session_t *session; /* Create session using the "uni2" profile (MRCPv2) */ session = mrcp_application_session_create(app, "uni2", user_data); if (!session) { printf("Failed to create MRCP session\n"); return NULL; } /* Set optional session name for debugging */ mrcp_application_session_name_set(session, "ASR-Session-001"); printf("Created MRCP session: %s\n", mrcp_application_session_id_get(session)->buf); return session; } /* Create session with custom memory pool */ mrcp_session_t* create_session_with_pool(mrcp_application_t *app, apr_pool_t *external_pool) { return mrcp_application_session_create_ex( app, "uni2", /* profile name */ NULL, /* user data */ TRUE, /* take ownership of pool */ external_pool /* external memory pool */ ); } ``` ``` -------------------------------- ### Link Libraries for Test Application Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Links the test application against necessary external and system libraries, with platform-specific configurations for Windows and Unix. ```cmake target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () ``` -------------------------------- ### Create Executable Target Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Defines the main executable for the test application, linking against other project targets. ```cmake add_executable (${PROJECT_NAME} ${MPF_TEST_SOURCES} $ $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "tests") ``` -------------------------------- ### Specify Source Files for asrclient Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Lists the source files required to build the asrclient application. The 'src' directory is used for the main source file. ```cmake set (ASR_CLIENT_SOURCES src/main.c ) source_group ("src" FILES ${ASR_CLIENT_SOURCES}) ``` -------------------------------- ### Implement a Custom MRCP Engine Plugin for UniMRCP Source: https://context7.com/unispeech/unimrcp/llms.txt Provides the basic structure for creating a custom MRCP engine plugin. This includes defining engine methods and the plugin entry point. Ensure MRCP_PLUGIN_VERSION_DECLARE and MRCP_PLUGIN_LOG_SOURCE_IMPLEMENT are correctly set. ```c #include "mrcp_engine_plugin.h" #include "mrcp_recog_engine.h" #include "apt_consumer_task.h" #include "apt_log.h" /* Declare plugin version - REQUIRED */ MRCP_PLUGIN_VERSION_DECLARE /* Declare log source for plugin-specific logging */ MRCP_PLUGIN_LOG_SOURCE_IMPLEMENT(MY_PLUGIN, "MY-PLUGIN") #define MY_LOG_MARK APT_LOG_MARK_DECLARE(MY_PLUGIN) /* Engine data structure */ typedef struct my_engine_t { apt_consumer_task_t *task; /* Custom engine data */ } my_engine_t; /* Engine method implementations */ static apt_bool_t my_engine_destroy(mrcp_engine_t *engine) { my_engine_t *my_engine = engine->obj; if (my_engine->task) { apt_task_t *task = apt_consumer_task_base_get(my_engine->task); apt_task_destroy(task); } return TRUE; } static apt_bool_t my_engine_open(mrcp_engine_t *engine) { my_engine_t *my_engine = engine->obj; if (my_engine->task) { apt_task_t *task = apt_consumer_task_base_get(my_engine->task); apt_task_start(task); } return mrcp_engine_open_respond(engine, TRUE); } static apt_bool_t my_engine_close(mrcp_engine_t *engine) { my_engine_t *my_engine = engine->obj; if (my_engine->task) { apt_task_t *task = apt_consumer_task_base_get(my_engine->task); apt_task_terminate(task, TRUE); } return mrcp_engine_close_respond(engine); } static mrcp_engine_channel_t* my_engine_channel_create( mrcp_engine_t *engine, apr_pool_t *pool) { /* Create and return engine channel */ /* See channel implementation below */ return NULL; } static const mrcp_engine_method_vtable_t engine_vtable = { my_engine_destroy, my_engine_open, my_engine_close, my_engine_channel_create }; /* Plugin entry point - REQUIRED */ MRCP_PLUGIN_DECLARE(mrcp_engine_t*) mrcp_plugin_create(apr_pool_t *pool) { my_engine_t *my_engine; apt_task_t *task; apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; /* Allocate engine */ my_engine = apr_palloc(pool, sizeof(my_engine_t)); /* Create consumer task for async processing */ msg_pool = apt_task_msg_pool_create_dynamic(sizeof(void*), pool); my_engine->task = apt_consumer_task_create(my_engine, msg_pool, pool); if (my_engine->task) { task = apt_consumer_task_base_get(my_engine->task); apt_task_name_set(task, "My Engine Task"); } apt_log(MY_LOG_MARK, APT_PRIO_INFO, "My Plugin Created"); /* Create engine base */ return mrcp_engine_create( MRCP_RECOGNIZER_RESOURCE, /* or MRCP_SYNTHESIZER_RESOURCE */ my_engine, &engine_vtable, pool ); } ``` -------------------------------- ### Configure Include Directories for asrclient Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Specifies the directories where the compiler should look for header files. This includes project-specific headers and headers for various UniMRCP and third-party libraries. ```cmake include_directories ( ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/../libasr-client/include ${UNIMRCP_CLIENT_INCLUDE_DIRS} ${MRCP_CLIENT_INCLUDE_DIRS} ${MRCP_SIGNALING_INCLUDE_DIRS} ${MRCPv2_TRANSPORT_INCLUDE_DIRS} ${MRCP_INCLUDE_DIRS} ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Creating a Control Channel Source: https://context7.com/unispeech/unimrcp/llms.txt Explains how to create an MRCP control channel for a specific resource type (e.g., recognizer) within an existing session using `mrcp_application_channel_create()`. ```APIDOC ## Creating a Control Channel The `mrcp_application_channel_create()` function creates an MRCP control channel for a specific resource type within a session. ```c #include "mrcp_application.h" #include "mrcp_recog_resource.h" /* Audio stream callbacks for recognition */ static apt_bool_t stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame) { /* Read audio frames from source (e.g., file, microphone) */ FILE *audio_file = stream->obj; if (audio_file) { size_t bytes_read = fread(frame->codec_frame.buffer, 1, frame->codec_frame.size, audio_file); if (bytes_read == frame->codec_frame.size) { frame->type |= MEDIA_FRAME_TYPE_AUDIO; } } return TRUE; } static const mpf_audio_stream_vtable_t stream_vtable = { NULL, /* destroy */ NULL, /* open */ NULL, /* close */ stream_read, /* read */ NULL, /* write */ NULL, NULL, NULL }; mrcp_channel_t* create_recognizer_channel(mrcp_session_t *session, FILE *audio_file) { mpf_termination_t *termination; mpf_stream_capabilities_t *caps; mrcp_channel_t *channel; apr_pool_t *pool = mrcp_application_session_pool_get(session); /* Create stream capabilities */ caps = mpf_source_stream_capabilities_create(pool); mpf_codec_capabilities_add(&caps->codecs, MPF_SAMPLE_RATE_8000 | MPF_SAMPLE_RATE_16000, "LPCM"); /* Create audio termination */ termination = mrcp_application_audio_termination_create( session, &stream_vtable, caps, audio_file /* object passed to stream callbacks */ ); /* Create recognizer channel */ channel = mrcp_application_channel_create( session, MRCP_RECOGNIZER_RESOURCE, /* resource type */ termination, NULL, /* RTP descriptor (NULL for default) */ NULL /* user data */ ); return channel; } ``` ``` -------------------------------- ### Send RECOGNITION-COMPLETE Event in C Source: https://context7.com/unispeech/unimrcp/llms.txt Sends an asynchronous recognition complete event from a plugin channel. Requires a valid channel structure and completion cause. ```c #include "mrcp_recog_header.h" apt_bool_t send_recognition_complete(my_channel_t *my_channel, mrcp_recog_completion_cause_e cause, const char *result_xml) { mrcp_message_t *event; mrcp_recog_header_t *recog_header; mrcp_generic_header_t *generic_header; if (!my_channel->recog_request) { return FALSE; } /* Create RECOGNITION-COMPLETE event */ event = mrcp_event_create( my_channel->recog_request, RECOGNIZER_RECOGNITION_COMPLETE, my_channel->recog_request->pool ); if (!event) { return FALSE; } /* Set completion cause */ recog_header = mrcp_resource_header_prepare(event); if (recog_header) { recog_header->completion_cause = cause; mrcp_resource_header_property_add(event, RECOGNIZER_HEADER_COMPLETION_CAUSE); } /* Set result body if success */ if (cause == RECOGNIZER_COMPLETION_CAUSE_SUCCESS && result_xml) { generic_header = mrcp_generic_header_prepare(event); if (generic_header) { apt_string_assign(&generic_header->content_type, "application/x-nlsml", event->pool); mrcp_generic_header_property_add(event, GENERIC_HEADER_CONTENT_TYPE); } apt_string_assign(&event->body, result_xml, event->pool); } /* Mark request as complete */ event->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE; my_channel->recog_request = NULL; /* Send event */ return mrcp_engine_channel_message_send(my_channel->channel, event); } /* Example NLSML result */ const char *nlsml_result = "\n" "\n" " \n" " one\n" " one\n" " \n" ""; ``` -------------------------------- ### Create MRCP Client Source: https://context7.com/unispeech/unimrcp/llms.txt Creates an MRCP client instance using XML configuration from the specified directory layout. Registers an application message handler to process incoming messages. ```c #include "unimrcp_client.h" #include "mrcp_application.h" #include "apt_dir_layout.h" /* Application message handler callback */ static apt_bool_t app_message_handler(const mrcp_app_message_t *app_message) { /* Process incoming messages from MRCP server */ switch (app_message->message_type) { case MRCP_APP_MESSAGE_TYPE_SIGNALING: printf("Received signaling message\n"); break; case MRCP_APP_MESSAGE_TYPE_CONTROL: printf("Received MRCP control message\n"); break; } return TRUE; } mrcp_client_t* create_mrcp_client(const char *root_dir) { apr_pool_t *pool; apt_dir_layout_t *dir_layout; mrcp_client_t *client; mrcp_application_t *app; apr_pool_create(&pool, NULL); dir_layout = apt_default_dir_layout_create(root_dir, pool); /* Create MRCP client from XML configuration */ client = unimrcp_client_create(dir_layout); if (!client) { printf("Failed to create MRCP client\n"); return NULL; } /* Create application instance */ app = mrcp_application_create(app_message_handler, NULL, pool); /* Register application with client */ mrcp_client_application_register(client, app, "demo-app"); /* Start the client */ mrcp_client_start(client); return client; } ``` -------------------------------- ### Configure UniMRCP mrcpsignaling Library Build Source: https://github.com/unispeech/unimrcp/blob/master/libs/mrcp-signaling/CMakeLists.txt This CMake script configures the build for the mrcpsignaling library. It sets up header and source files, defines preprocessor macros, and specifies include directories necessary for compilation. ```cmake cmake_minimum_required (VERSION 2.8) project (mrcpsignaling) # Set header files set (MRCP_SIGNALING_HEADERS include/mrcp_sig_types.h include/mrcp_sig_agent.h include/mrcp_session.h include/mrcp_session_descriptor.h ) source_group ("include" FILES ${MRCP_SIGNALING_HEADERS}) # Set source files set (MRCP_SIGNALING_SOURCES src/mrcp_sig_agent.c src/mrcp_session_descriptor.c ) source_group ("src" FILES ${MRCP_SIGNALING_SOURCES}) # Library declaration add_library (${PROJECT_NAME} OBJECT ${MRCP_SIGNALING_SOURCES} ${MRCP_SIGNALING_HEADERS}) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "libs") # Preprocessor definitions add_definitions ( ${MRCP_DEFINES} ${MPF_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${MRCP_INCLUDE_DIRS} ${MPF_INCLUDE_DIRS} ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Configure CMake for apttest Source: https://github.com/unispeech/unimrcp/blob/master/tests/apttest/CMakeLists.txt Defines the project structure, source files, and build dependencies for the apttest executable. ```cmake cmake_minimum_required (VERSION 2.8) project (apttest) # Set source files set (APT_TEST_SOURCES src/main.c src/task_suite.c src/consumer_task_suite.c src/multipart_suite.c ) source_group ("src" FILES ${APT_TEST_SOURCES}) # Application declaration add_executable (${PROJECT_NAME} ${APT_TEST_SOURCES} $ ) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "tests") # Input libraries target_link_libraries(${PROJECT_NAME} ${APU_LIBRARIES} ${APR_LIBRARIES} ) # Input system libraries if (WIN32) target_link_libraries(${PROJECT_NAME} ws2_32 winmm) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m) endif () # Preprocessor definitions add_definitions ( ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) # Include directories include_directories ( ${PROJECT_SOURCE_DIR}/include ${APR_TOOLKIT_INCLUDE_DIRS} ${APR_INCLUDE_DIRS} ${APU_INCLUDE_DIRS} ) ``` -------------------------------- ### Declare asrclient Executable Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Defines the asrclient application as an executable target using the specified source files. Sets properties for the executable's folder and output name. ```cmake add_executable (${PROJECT_NAME} ${ASR_CLIENT_SOURCES}) set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "platforms") set_target_properties (${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_OUTPUT_NAME}) ``` -------------------------------- ### Add Channels to Sessions Source: https://context7.com/unispeech/unimrcp/llms.txt Initiates the channel addition process and handles the asynchronous response via a message dispatcher. ```c #include "mrcp_application.h" /* Message dispatcher callbacks */ static apt_bool_t on_channel_add(mrcp_application_t *app, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status) { if (status == MRCP_SIG_STATUS_CODE_SUCCESS) { printf("Channel added successfully\n"); /* Now we can send MRCP requests on this channel */ /* e.g., send RECOGNIZE request */ } else { printf("Failed to add channel: %d\n", status); } return TRUE; } static mrcp_app_message_dispatcher_t dispatcher = { NULL, /* on_session_update */ NULL, /* on_session_terminate */ on_channel_add, /* on_channel_add */ NULL, /* on_channel_remove */ NULL, /* on_message_receive */ NULL, /* on_terminate_event */ NULL /* on_resource_discover */ }; apt_bool_t add_channel_to_session(mrcp_session_t *session, mrcp_channel_t *channel) { /* Request to add channel - async response via on_channel_add */ return mrcp_application_channel_add(session, channel); } ``` -------------------------------- ### Define asrclient Application Output Name Source: https://github.com/unispeech/unimrcp/blob/master/platforms/asr-client/CMakeLists.txt Sets the desired output name for the asrclient executable. This allows for a different executable name than the project name. ```cmake set (PROJECT_OUTPUT_NAME asrclient) ``` -------------------------------- ### Set Preprocessor Definitions Source: https://github.com/unispeech/unimrcp/blob/master/tests/mpftest/CMakeLists.txt Adds preprocessor definitions required for the build, including project-specific and library-related defines. ```cmake add_definitions ( ${MPF_DEFINES} ${APR_TOOLKIT_DEFINES} ${APR_DEFINES} ${APU_DEFINES} ) ```