Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
6eb2276c
提交
6eb2276c
authored
10月 11, 2018
作者:
Chris Rienzo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-11453 [mod_rayo] add support for FS JSON ASR result.
上级
101512ba
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
113 行增加
和
32 行删除
+113
-32
nlsml.c
src/mod/event_handlers/mod_rayo/nlsml.c
+41
-28
nlsml.h
src/mod/event_handlers/mod_rayo/nlsml.h
+1
-0
rayo_input_component.c
src/mod/event_handlers/mod_rayo/rayo_input_component.c
+68
-1
Makefile
src/mod/event_handlers/mod_rayo/test_nlsml/Makefile
+3
-3
没有找到文件。
src/mod/event_handlers/mod_rayo/nlsml.c
浏览文件 @
6eb2276c
/*
/*
* mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2013-201
4
, Grasshopper
* Copyright (C) 2013-201
8
, Grasshopper
*
*
* Version: MPL 1.1
* Version: MPL 1.1
*
*
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <iksemel.h>
#include <iksemel.h>
#include "nlsml.h"
#include "nlsml.h"
#include "iks_helpers.h"
struct
nlsml_parser
;
struct
nlsml_parser
;
...
@@ -417,51 +418,63 @@ static int isdtmf(const char digit)
...
@@ -417,51 +418,63 @@ static int isdtmf(const char digit)
}
}
/**
/**
* Construct an NLSML result for
digit
match
* Construct an NLSML result for match
* @param
digits the matching digits
* @param
match the matching digits or text
* @param interpretation the optional digit interpretation
* @param interpretation the optional digit interpretation
* @param mode dtmf or speech
* @param confidence 0-100
* @return the NLSML <result>
* @return the NLSML <result>
*/
*/
iks
*
nlsml_create_
dtmf_match
(
const
char
*
digits
,
const
char
*
interpretation
)
iks
*
nlsml_create_
match
(
const
char
*
match
,
const
char
*
interpretation
,
const
char
*
mode
,
int
confidence
)
{
{
iks
*
result
=
iks_new
(
"result"
);
iks
*
result
=
iks_new
(
"result"
);
iks_insert_attrib
(
result
,
"xmlns"
,
NLSML_NS
);
iks_insert_attrib
(
result
,
"xmlns"
,
NLSML_NS
);
iks_insert_attrib
(
result
,
"xmlns:xf"
,
"http://www.w3.org/2000/xforms"
);
iks_insert_attrib
(
result
,
"xmlns:xf"
,
"http://www.w3.org/2000/xforms"
);
if
(
!
zstr
(
digits
))
{
if
(
!
zstr
(
match
))
{
int
first
=
1
;
int
i
;
int
num_digits
=
strlen
(
digits
);
switch_stream_handle_t
stream
=
{
0
};
iks
*
interpretation_node
=
iks_insert
(
result
,
"interpretation"
);
iks
*
interpretation_node
=
iks_insert
(
result
,
"interpretation"
);
iks
*
input_node
=
iks_insert
(
interpretation_node
,
"input"
);
iks
*
input_node
=
iks_insert
(
interpretation_node
,
"input"
);
iks
*
instance_node
=
iks_insert
(
interpretation_node
,
"instance"
);
iks
*
instance_node
=
iks_insert
(
interpretation_node
,
"instance"
);
iks_insert_attrib
(
input_node
,
"mode"
,
"dtmf"
);
iks_insert_attrib
(
input_node
,
"mode"
,
mode
);
iks_insert_attrib
(
input_node
,
"confidence"
,
"100"
);
iks_insert_attrib_printf
(
input_node
,
"confidence"
,
"%d"
,
confidence
);
iks_insert_cdata
(
input_node
,
match
,
strlen
(
match
));
SWITCH_STANDARD_STREAM
(
stream
);
for
(
i
=
0
;
i
<
num_digits
;
i
++
)
{
if
(
isdtmf
(
digits
[
i
]))
{
if
(
first
)
{
stream
.
write_function
(
&
stream
,
"%c"
,
digits
[
i
]);
first
=
0
;
}
else
{
stream
.
write_function
(
&
stream
,
" %c"
,
digits
[
i
]);
}
}
}
iks_insert_cdata
(
input_node
,
stream
.
data
,
strlen
(
stream
.
data
));
if
(
zstr
(
interpretation
))
{
if
(
zstr
(
interpretation
))
{
iks_insert_cdata
(
instance_node
,
stream
.
data
,
strlen
(
stream
.
data
));
iks_insert_cdata
(
instance_node
,
match
,
strlen
(
match
));
}
else
{
}
else
{
iks_insert_cdata
(
instance_node
,
interpretation
,
strlen
(
interpretation
));
iks_insert_cdata
(
instance_node
,
interpretation
,
strlen
(
interpretation
));
}
}
switch_safe_free
(
stream
.
data
);
}
}
return
result
;
return
result
;
}
}
/**
* Construct an NLSML result for match
* @param match the matching digits or text
* @param interpretation the optional digit interpretation
* @return the NLSML <result>
*/
iks
*
nlsml_create_dtmf_match
(
const
char
*
digits
,
const
char
*
interpretation
)
{
iks
*
result
=
NULL
;
int
first
=
1
;
int
i
;
int
num_digits
=
strlen
(
digits
);
switch_stream_handle_t
stream
=
{
0
};
SWITCH_STANDARD_STREAM
(
stream
);
for
(
i
=
0
;
i
<
num_digits
;
i
++
)
{
if
(
isdtmf
(
digits
[
i
]))
{
if
(
first
)
{
stream
.
write_function
(
&
stream
,
"%c"
,
digits
[
i
]);
first
=
0
;
}
else
{
stream
.
write_function
(
&
stream
,
" %c"
,
digits
[
i
]);
}
}
}
result
=
nlsml_create_match
((
const
char
*
)
stream
.
data
,
interpretation
,
"dtmf"
,
100
);
switch_safe_free
(
stream
.
data
);
return
result
;
}
/**
/**
* Initialize NLSML parser. This function is not thread safe.
* Initialize NLSML parser. This function is not thread safe.
*/
*/
...
...
src/mod/event_handlers/mod_rayo/nlsml.h
浏览文件 @
6eb2276c
...
@@ -44,6 +44,7 @@ extern void nlsml_destroy(void);
...
@@ -44,6 +44,7 @@ extern void nlsml_destroy(void);
enum
nlsml_match_type
nlsml_parse
(
const
char
*
result
,
const
char
*
uuid
);
enum
nlsml_match_type
nlsml_parse
(
const
char
*
result
,
const
char
*
uuid
);
iks
*
nlsml_normalize
(
const
char
*
result
);
iks
*
nlsml_normalize
(
const
char
*
result
);
extern
iks
*
nlsml_create_dtmf_match
(
const
char
*
digits
,
const
char
*
interpretation
);
extern
iks
*
nlsml_create_dtmf_match
(
const
char
*
digits
,
const
char
*
interpretation
);
extern
iks
*
nlsml_create_match
(
const
char
*
digits
,
const
char
*
interpretation
,
const
char
*
mode
,
int
confidence
);
#endif
#endif
...
...
src/mod/event_handlers/mod_rayo/rayo_input_component.c
浏览文件 @
6eb2276c
...
@@ -876,6 +876,30 @@ static iks *start_timers_call_input_component(struct rayo_actor *component, stru
...
@@ -876,6 +876,30 @@ static iks *start_timers_call_input_component(struct rayo_actor *component, stru
return
iks_new_iq_result
(
iq
);
return
iks_new_iq_result
(
iq
);
}
}
/**
* Get text / error from result
*/
static
const
char
*
get_detected_speech_result_text
(
cJSON
*
result_json
,
double
*
confidence
,
const
char
**
error_text
)
{
const
char
*
result_text
=
NULL
;
const
char
*
text
=
cJSON_GetObjectCstr
(
result_json
,
"text"
);
if
(
confidence
)
{
*
confidence
=
0
.
0
;
}
if
(
!
zstr
(
text
))
{
cJSON
*
json_confidence
=
cJSON_GetObjectItem
(
result_json
,
"confidence"
);
if
(
json_confidence
&&
json_confidence
->
valuedouble
>
0
.
0
)
{
*
confidence
=
json_confidence
->
valuedouble
;
}
else
{
*
confidence
=
100
.
0
;
}
result_text
=
text
;
}
else
if
(
error_text
)
{
*
error_text
=
cJSON_GetObjectCstr
(
result_json
,
"error"
);
}
return
result_text
;
}
/**
/**
* Handle speech detection event
* Handle speech detection event
*/
*/
...
@@ -905,7 +929,50 @@ static void on_detected_speech_event(switch_event_t *event)
...
@@ -905,7 +929,50 @@ static void on_detected_speech_event(switch_event_t *event)
if
(
zstr
(
result
))
{
if
(
zstr
(
result
))
{
rayo_component_send_complete
(
component
,
INPUT_NOMATCH
);
rayo_component_send_complete
(
component
,
INPUT_NOMATCH
);
}
else
{
}
else
{
if
(
strchr
(
result
,
'<'
))
{
if
(
result
[
0
]
==
'{'
)
{
// internal FS JSON format
cJSON
*
json_result
=
cJSON_Parse
(
result
);
if
(
json_result
)
{
// examine result to determine what happened
double
confidence
=
0
.
0
;
const
char
*
error_text
=
NULL
;
const
char
*
result_text
=
NULL
;
result_text
=
get_detected_speech_result_text
(
json_result
,
&
confidence
,
&
error_text
);
if
(
!
zstr
(
result_text
))
{
// got result... send as NLSML
iks
*
result
=
nlsml_create_match
(
result_text
,
NULL
,
"speech"
,
(
int
)
confidence
);
/* notify of match */
switch_log_printf
(
SWITCH_CHANNEL_UUID_LOG
(
uuid
),
SWITCH_LOG_DEBUG
,
"MATCH = %s
\n
"
,
result_text
);
send_match_event
(
RAYO_COMPONENT
(
component
),
result
);
iks_delete
(
result
);
}
else
if
(
zstr
(
error_text
))
{
// unknown error
switch_log_printf
(
SWITCH_CHANNEL_UUID_LOG
(
uuid
),
SWITCH_LOG_WARNING
,
"No matching text nor error in result: %s!
\n
"
,
result
);
rayo_component_send_complete
(
component
,
INPUT_NOMATCH
);
}
else
if
(
!
strcmp
(
error_text
,
"no_input"
))
{
// no input error
rayo_component_send_complete
(
component
,
INPUT_NOINPUT
);
}
else
if
(
!
strcmp
(
error_text
,
"no_match"
))
{
// no match error
rayo_component_send_complete
(
component
,
INPUT_NOMATCH
);
}
else
{
// generic error
iks
*
response
=
rayo_component_create_complete_event
(
component
,
COMPONENT_COMPLETE_ERROR
);
iks
*
error
=
NULL
;
if
((
error
=
iks_find
(
response
,
"complete"
)))
{
if
((
error
=
iks_find
(
error
,
"error"
)))
{
iks_insert_cdata
(
error
,
error_text
,
strlen
(
error_text
));
}
}
rayo_component_send_complete_event
(
component
,
response
);
}
cJSON_Delete
(
json_result
);
}
else
{
// failed to parse JSON result
switch_log_printf
(
SWITCH_CHANNEL_UUID_LOG
(
uuid
),
SWITCH_LOG_WARNING
,
"Failed to parse JSON result: %s!
\n
"
,
result
);
rayo_component_send_complete
(
component
,
INPUT_NOMATCH
);
}
}
else
if
(
strchr
(
result
,
'<'
))
{
/* got an XML result */
/* got an XML result */
enum
nlsml_match_type
match_type
=
nlsml_parse
(
result
,
uuid
);
enum
nlsml_match_type
match_type
=
nlsml_parse
(
result
,
uuid
);
switch
(
match_type
)
{
switch
(
match_type
)
{
...
...
src/mod/event_handlers/mod_rayo/test_nlsml/Makefile
浏览文件 @
6eb2276c
...
@@ -3,7 +3,7 @@ BASE=../../../../..
...
@@ -3,7 +3,7 @@ BASE=../../../../..
IKS_DIR
=
$(BASE)
/libs/iksemel
IKS_DIR
=
$(BASE)
/libs/iksemel
IKS_LA
=
$(IKS_DIR)
/src/libiksemel.la
IKS_LA
=
$(IKS_DIR)
/src/libiksemel.la
LOCAL_CFLAGS
+=
-I
../
-I
$(BASE)
/libs/iksemel/include
LOCAL_CFLAGS
+=
-I
../
-I
$(BASE)
/libs/iksemel/include
LOCAL_OBJS
=
$(PCRE_LA)
$(IKS_LA)
main.o ../nlsml.o
LOCAL_OBJS
=
$(PCRE_LA)
$(IKS_LA)
main.o ../nlsml.o
../iks_helpers.o
LOCAL_SOURCES
=
main.c
LOCAL_SOURCES
=
main.c
include
$(BASE)/build/modmake.rules
include
$(BASE)/build/modmake.rules
...
@@ -12,7 +12,7 @@ $(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update
...
@@ -12,7 +12,7 @@ $(IKS_LA): $(IKS_DIR) $(IKS_DIR)/.update
@
$(TOUCH_TARGET)
@
$(TOUCH_TARGET)
local_all
:
local_all
:
libtool
--mode
=
link
gcc main.o ../nlsml.o
-o
test
test_nlsml.la
libtool
--mode
=
link
gcc main.o ../nlsml.o
../iks_helpers.o test_nlsml.la ../../../../../.libs/libfreeswitch.la ../../../../../libs/iksemel/src/.libs/libiksemel.a
-lpcre
-lssl
-lcrypto
-g
-ggdb
-O2
-pthread
-o
test
local_clean
:
local_clean
:
-
rm test
-
rm test
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论