switch_core_asr.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Willie Zhang <zhanghong905011@163.com>
  26. *
  27. * switch_core_asr.c -- tests file core functions
  28. *
  29. */
  30. #include <switch.h>
  31. #include <stdlib.h>
  32. #include <test/switch_test.h>
  33. FST_CORE_BEGIN("./conf")
  34. {
  35. FST_SUITE_BEGIN(switch_core_asr)
  36. {
  37. FST_SETUP_BEGIN()
  38. {
  39. fst_requires_module("mod_test");
  40. fst_requires_module("mod_tone_stream");
  41. }
  42. FST_SETUP_END()
  43. FST_TEARDOWN_BEGIN()
  44. {
  45. }
  46. FST_TEARDOWN_END()
  47. FST_TEST_BEGIN(core_asr_feed_resample)
  48. {
  49. uint8_t *buf;
  50. size_t len = 960;
  51. char input_filename[1024];
  52. const char* session_id = "123456";
  53. switch_asr_handle_t ah = { 0 };
  54. switch_file_handle_t file_handle = { 0 };
  55. switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
  56. char *grammar = switch_core_sprintf(fst_pool, "{start-input-timers=true,no-input-timeout=5000,speech-timeout=10000,channel-uuid=%s}default", session_id);
  57. fst_requires(fst_core > 1)
  58. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Open recognizer\n");
  59. fst_requires(switch_core_asr_open(&ah, "test", "L16", 48000, "", &flags, fst_pool) == SWITCH_STATUS_SUCCESS);
  60. sprintf(input_filename, "%s", "silence_stream://100,0");
  61. file_handle.channels = 1;
  62. file_handle.native_rate = 48000;
  63. fst_requires(switch_core_asr_load_grammar(&ah, grammar, "") == SWITCH_STATUS_SUCCESS);
  64. fst_requires(switch_core_file_open(&file_handle, input_filename, file_handle.channels, 48000, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS);
  65. buf = (uint8_t *)switch_core_alloc(fst_pool, sizeof(uint8_t) * 960 * sizeof(uint16_t) * file_handle.channels);
  66. fst_requires(switch_core_file_read(&file_handle, buf, &len) == SWITCH_STATUS_SUCCESS);
  67. fst_requires(switch_core_asr_feed(&ah, buf, len * sizeof(int16_t), &flags) == SWITCH_STATUS_SUCCESS);
  68. fst_check(ah.resampler->to_len == 320);
  69. fst_requires(switch_core_file_close(&file_handle) == SWITCH_STATUS_SUCCESS);
  70. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Close recognizer\n");
  71. flags = SWITCH_ASR_FLAG_NONE;
  72. fst_requires(switch_core_asr_close(&ah, &flags) == SWITCH_STATUS_SUCCESS);
  73. }
  74. FST_TEST_END()
  75. }
  76. FST_SUITE_END()
  77. }
  78. FST_CORE_END()