Feature/soniox (#40)

* changes for soniox STT

* add patch for mod_httapi to handle signed AWS URLs
This commit is contained in:
Dave Horton
2023-03-03 20:06:53 -05:00
committed by GitHub
parent e18c562409
commit 2d40dc0929
12 changed files with 235 additions and 19 deletions
@@ -402,6 +402,7 @@ libs/googleapis/gens/google/cloud/dialogflow/v2beta1/webhook.pb.cc
libfreeswitch_libgoogleapis_la_CPPFLAGS = -I/usr/local/include -I$(GOOGLEAPIS_GENS_PATH) -std=c++17 -pthread
# nuance asr
NUANCE_GENS_PATH = libs/nuance-asr-grpc-api/stubs/
nodist_libfreeswitch_libnuanceapis_la_SOURCES = \
@@ -420,6 +421,7 @@ libs/nuance-asr-grpc-api/stubs/nuance/asr/v1/recognizer.grpc.pb.cc
libfreeswitch_libnuanceapis_la_CPPFLAGS = -I/usr/local/include -I$(NUANCE_GENS_PATH) -std=c++17 -pthread
#nvidia asr
NVIDIA_GENS_PATH = libs/riva-asr-grpc-api/stubs/
nodist_libfreeswitch_libnvidiaapis_la_SOURCES = \
@@ -430,8 +432,17 @@ libs/riva-asr-grpc-api/stubs/riva/proto/riva_audio.grpc.pb.cc
libfreeswitch_libnvidiaapis_la_CPPFLAGS = -I/usr/local/include -I$(NVIDIA_GENS_PATH) -std=c++17 -pthread
CORE_LIBS+=libfreeswitch_libgoogleapis.la libfreeswitch_libnuanceapis.la libfreeswitch_libnvidiaapis.la
noinst_LTLIBRARIES += libfreeswitch_libgoogleapis.la libfreeswitch_libnuanceapis.la libfreeswitch_libnvidiaapis.la
#soniox asr
SONIOX_GENS_PATH = libs/soniox-asr-grpc-api/stubs/
nodist_libfreeswitch_libsonioxapis_la_SOURCES = \
libs/soniox-asr-grpc-api/stubs/soniox/speech_service.pb.cc \
libs/soniox-asr-grpc-api/stubs/soniox/speech_service.grpc.pb.cc
libfreeswitch_libsonioxapis_la_CPPFLAGS = -I/usr/local/include -I$(SONIOX_GENS_PATH) -std=c++17 -pthread
CORE_LIBS+=libfreeswitch_libgoogleapis.la libfreeswitch_libnuanceapis.la libfreeswitch_libnvidiaapis.la libfreeswitch_libsonioxapis.la
noinst_LTLIBRARIES += libfreeswitch_libgoogleapis.la libfreeswitch_libnuanceapis.la libfreeswitch_libnvidiaapis.la libfreeswitch_libsonioxapis.la
endif
@@ -0,0 +1,73 @@
<configuration name="avmd.conf" description="AVMD config">
<settings>
<!-- Edit these settings to change default behaviour
of each avmd session. Settings can be overwritten
by values passed dynamically per each session -->
<!-- Global settings -->
<!-- define/undefine this to enable/disable logging of avmd
intermediate computations to log -->
<param name="debug" value="0"/>
<!-- define/undef this to enable/disable verbose logging (and reporting to the console)
of detection status and other diagnostics like parameters avmd session has been started with,
change of configuration parameters, beep detection status after session ended
(stop event is fired independently of this setting and beep status included there) -->
<param name="report_status" value="1"/>
<!-- define/undefine this to enable/disable faster computation
of arcus cosine - table will be created mapping floats
to integers and returning arc cos values given these integer
indices into table -->
<param name="fast_math" value="0"/>
<!-- Global settings end -->
<!-- Per call (session) settings. These settings can be overwritten
with custom/different values per each avmd session -->
<!-- define/undefine this to classify avmd beep detection as valid
only when there is required number of consecutive elements
in the SMA buffer without reset -->
<param name="require_continuous_streak" value="1"/>
<!-- required number of consecutive elements in the SMA buffer
without reset. This parameter helps to avoid false beeps, bigger this value is
smaller the probability of getting false detection -->
<param name="sample_n_continuous_streak" value="3"/>
<!-- define number of samples to skip starting from the beginning
of the frame and/or after reset has happened. This serves the purpose of skipping first few
estimations on each frame, as these estimations may be inaccurate. This parameter also helps
to give more robust detections when it's value is increased (up to scertain limit of about 60). -->
<param name="sample_n_to_skip" value="0"/>
<param name="require_continuous_streak_amp" value="1"/>
<param name="sample_n_continuous_streak_amp" value="3"/>
<!-- define/undefine this to enable/disable simplified estimation
of frequency based on approximation of sin(x) with (x)
in the range x=[0,PI/2] -->
<param name="simplified_estimation" value="1"/>
<!-- define/undefine to enable/disable avmd on internal channel -->
<param name="inbound_channel" value="1"/>
<!-- define/undefine to enable/disable avmd on external channel -->
<param name="outbound_channel" value="0"/>
<!-- determines the mode of detection, default is both amplitude and frequency -->
<param name="detection_mode" value="2"/>
<!-- number of detection threads running per each avmd session -->
<param name="detectors_n" value="36"/>
<!-- number of lagged detection threads running per each avmd session -->
<param name="detectors_lagged_n" value="1"/>
<!-- Per call settings end -->
</settings>
</configuration>
@@ -1898,6 +1898,7 @@ AC_CONFIG_FILES([Makefile
src/mod/applications/mod_ibm_transcribe/Makefile
src/mod/applications/mod_nuance_transcribe/Makefile
src/mod/applications/mod_nvidia_transcribe/Makefile
src/mod/applications/mod_soniox_transcribe/Makefile
src/mod/applications/mod_dialogflow/Makefile
src/mod/applications/mod_abstraction/Makefile
src/mod/applications/mod_avmd/Makefile
@@ -18,13 +18,14 @@ module.exports = {
ENABLE_DATADOG_METRICS: 0,
JAMBONES_NETWORK_CIDR: '172.31.32.0/24',
JAMBONES_MYSQL_HOST: '${JAMBONES_MYSQL_HOST}',
JAMBONES_GATHER_EARLY_HINTS_MATCH: 1,
JAMBONES_MYSQL_USER: '${JAMBONES_MYSQL_USER}',
JAMBONES_MYSQL_PASSWORD: '${JAMBONES_MYSQL_PASSWORD}',
JAMBONES_MYSQL_DATABASE: 'jambones',
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_LOGLEVEL: 'debug',
JAMBONES_LOGLEVEL: 'info',
HTTP_PORT: 4001,
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9023,
@@ -0,0 +1,55 @@
--- mod_httapi.c 2023-03-01 13:57:28
+++ mod_httapi.c.new 2023-03-01 14:19:34
@@ -2472,6 +2472,12 @@
char *ua = NULL;
const char *profile_name = NULL;
int tries = 10;
+ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL &&
+ strstr(url, "X-Amz-Algorithm") != NULL &&
+ strstr(url, "X-Amz-Credential") != NULL &&
+ strstr(url, "X-Amz-Date") != NULL &&
+ strstr(url, "X-Amz-Expires") != NULL &&
+ strstr(url, "X-Amz-SignedHeaders") != NULL;
if (context->url_params) {
profile_name = switch_event_get_header(context->url_params, "profile_name");
@@ -2614,7 +2620,7 @@
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) client);
} else {
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1);
- switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
+ if (!awsSignedUrl) switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
}
if (headers) {
@@ -2783,6 +2789,12 @@
char *metadata;
const char *ext = NULL;
const char *err_msg = NULL;
+ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL &&
+ strstr(url, "X-Amz-Algorithm") != NULL &&
+ strstr(url, "X-Amz-Credential") != NULL &&
+ strstr(url, "X-Amz-Date") != NULL &&
+ strstr(url, "X-Amz-Expires") != NULL &&
+ strstr(url, "X-Amz-SignedHeaders") != NULL;
load_cache_data(context, url);
@@ -2831,7 +2843,7 @@
if (!unreachable && !zstr(context->metadata)) {
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
- url,
+ awsSignedUrl ? context->cache_file : url,
switch_event_get_header_nil(headers, "last-modified"),
switch_event_get_header_nil(headers, "etag"),
switch_event_get_header_nil(headers, "content-length"),
@@ -2855,7 +2867,7 @@
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
- url,
+ awsSignedUrl ? context->cache_file : url,
switch_event_get_header_nil(headers, "last-modified"),
switch_event_get_header_nil(headers, "etag"),
switch_event_get_header_nil(headers, "content-length"),
@@ -8,6 +8,7 @@ applications/mod_google_transcribe
applications/mod_ibm_transcribe
applications/mod_nuance_transcribe
applications/mod_nvidia_transcribe
applications/mod_soniox_transcribe
applications/mod_dialogflow
#applications/mod_abstraction
#applications/mod_av
@@ -9,6 +9,7 @@
<load module="mod_ibm_transcribe"/>
<load module="mod_nuance_transcribe"/>
<load module="mod_nvidia_transcribe"/>
<load module="mod_soniox_transcribe"/>
<load module="mod_dialogflow"/>
<!-- Loggers (I'd load these first) -->
@@ -50,6 +50,7 @@ cd grpc && git checkout ${GRPC_VERSION} && cd ..
cd freeswitch/libs
git clone https://github.com/drachtio/nuance-asr-grpc-api.git -b main
git clone https://github.com/drachtio/riva-asr-grpc-api.git -b main
git clone https://github.com/drachtio/soniox-asr-grpc-api.git -b main
git clone https://github.com/freeswitch/spandsp.git -b master
git clone https://github.com/freeswitch/sofia-sip.git -b master
git clone https://github.com/dpirch/libfvad.git
@@ -73,7 +74,7 @@ sudo cp -r /usr/local/src/drachtio-freeswitch-modules/modules/mod_dialogflow /us
sudo sed -i -r -e 's/(.*AM_CFLAGS\))/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am
sudo sed -i -r -e 's/(.*-std=c++11)/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am
# copy Makefiles into place
# copy Makefiles and patches into place
cp /tmp/configure.ac.extra /usr/local/src/freeswitch/configure.ac
cp /tmp/Makefile.am.extra /usr/local/src/freeswitch/Makefile.am
cp /tmp/modules.conf.in.extra /usr/local/src/freeswitch/build/modules.conf.in
@@ -82,13 +83,16 @@ cp /tmp/avmd.conf.xml /usr/local/src/freeswitch/conf/vanilla/autoload_configs/av
cp /tmp/switch_rtp.c.patch /usr/local/src/freeswitch/src
cp /tmp/switch_core_media.c.patch /usr/local/src/freeswitch/src
cp /tmp/mod_avmd.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_avmd
cp /tmp/mod_httapi.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_httapi
# patch freeswitch
cd /usr/local/src/freeswitch/src
patch < switch_rtp.c.patch
patch < switch_core_media.c.patch
cd mod/applications/mod_avmd
cd /usr/local/src/freeswitch/src/mod/applications/mod_avmd
patch < mod_avmd.c.patch
cd /usr/local/src/freeswitch/src/mod/applications/mod_httapi
patch < mod_httapi.c.patch
# build libwebsockets
cd /usr/local/src/libwebsockets
@@ -144,6 +148,11 @@ echo "building protobuf stubs for nvidia riva asr"
cd /usr/local/src/freeswitch/libs/riva-asr-grpc-api
LANGUAGE=cpp make
# build soniox protobufs
echo "building protobuf stubs for sonioxasr"
cd /usr/local/src/freeswitch/libs/soniox-asr-grpc-api
LANGUAGE=cpp make
# build freeswitch
echo "building freeswitch"
cd /usr/local/src/freeswitch
@@ -170,3 +179,8 @@ sudo systemctl enable freeswitch
sudo cp /tmp/freeswitch_log_rotation /etc/cron.daily/freeswitch_log_rotation
sudo chown root:root /etc/cron.daily/freeswitch_log_rotation
sudo chmod a+x /etc/cron.daily/freeswitch_log_rotation
echo "downloading soniox root verification certificate"
cd /usr/local/freeswitch/certs
wget https://raw.githubusercontent.com/grpc/grpc/master/etc/roots.pem
+9 -9
View File
@@ -80,6 +80,15 @@
"type": "shell",
"script": "scripts/install_os_tuning.sh"
},
{
"type": "shell",
"environment_vars": [
"ARCH={{user `ami_base_image_arch`}}",
"MEDIA_SERVER_NAME={{user `mediaserver_name`}}",
"PREFERRED_CODEC_LIST={{user `preferred_codec_list`}}"
],
"script": "scripts/install_freeswitch.sh"
},
{
"type": "shell",
"script": "scripts/install_nodejs.sh"
@@ -98,15 +107,6 @@
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_telegraf`}}",
"script": "scripts/install_telegraf.sh"
},
{
"type": "shell",
"environment_vars": [
"ARCH={{user `ami_base_image_arch`}}",
"MEDIA_SERVER_NAME={{user `mediaserver_name`}}",
"PREFERRED_CODEC_LIST={{user `preferred_codec_list`}}"
],
"script": "scripts/install_freeswitch.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `drachtio_version`}}",
@@ -30,7 +30,7 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '127.0.0.1',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_LOGLEVEL: 'debug'
JAMBONES_LOGLEVEL: 'info'
}
},
{
@@ -190,7 +190,7 @@ module.exports = {
env: {
NODE_ENV: 'production',
JAMBONES_NETWORK_CIDR: 'PRIVATE_IP/32',
JAMBONES_LOGLEVEL: 'debug',
JAMBONES_LOGLEVEL: 'info',
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
DRACHTIO_SECRET: 'cymru',
@@ -271,6 +271,7 @@ module.exports = {
AWS_REGION: 'AWS_REGION_NAME',
JAMBONES_NETWORK_CIDR: 'PRIVATE_IP/32',
JAMBONES_API_BASE_URL: '--JAMBONES_API_BASE_URL--',
JAMBONES_GATHER_EARLY_HINTS_MATCH: 1,
JAMBONES_MYSQL_HOST: '127.0.0.1',
JAMBONES_MYSQL_USER: 'admin',
JAMBONES_MYSQL_PASSWORD: 'JambonzR0ck$',
@@ -278,7 +279,7 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '127.0.0.1',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_LOGLEVEL: 'debug',
JAMBONES_LOGLEVEL: 'info',
JAMBONES_TIME_SERIES_HOST: '127.0.0.1',
HTTP_PORT: 3000,
DRACHTIO_HOST: '127.0.0.1',
@@ -0,0 +1,55 @@
--- mod_httapi.c 2023-03-01 13:57:28
+++ mod_httapi.c.new 2023-03-01 14:19:34
@@ -2472,6 +2472,12 @@
char *ua = NULL;
const char *profile_name = NULL;
int tries = 10;
+ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL &&
+ strstr(url, "X-Amz-Algorithm") != NULL &&
+ strstr(url, "X-Amz-Credential") != NULL &&
+ strstr(url, "X-Amz-Date") != NULL &&
+ strstr(url, "X-Amz-Expires") != NULL &&
+ strstr(url, "X-Amz-SignedHeaders") != NULL;
if (context->url_params) {
profile_name = switch_event_get_header(context->url_params, "profile_name");
@@ -2614,7 +2620,7 @@
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) client);
} else {
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1);
- switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
+ if (!awsSignedUrl) switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
}
if (headers) {
@@ -2783,6 +2789,12 @@
char *metadata;
const char *ext = NULL;
const char *err_msg = NULL;
+ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL &&
+ strstr(url, "X-Amz-Algorithm") != NULL &&
+ strstr(url, "X-Amz-Credential") != NULL &&
+ strstr(url, "X-Amz-Date") != NULL &&
+ strstr(url, "X-Amz-Expires") != NULL &&
+ strstr(url, "X-Amz-SignedHeaders") != NULL;
load_cache_data(context, url);
@@ -2831,7 +2843,7 @@
if (!unreachable && !zstr(context->metadata)) {
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
- url,
+ awsSignedUrl ? context->cache_file : url,
switch_event_get_header_nil(headers, "last-modified"),
switch_event_get_header_nil(headers, "etag"),
switch_event_get_header_nil(headers, "content-length"),
@@ -2855,7 +2867,7 @@
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
- url,
+ awsSignedUrl ? context->cache_file : url,
switch_event_get_header_nil(headers, "last-modified"),
switch_event_get_header_nil(headers, "etag"),
switch_event_get_header_nil(headers, "content-length"),
@@ -73,7 +73,7 @@ sudo cp -r /usr/local/src/drachtio-freeswitch-modules/modules/mod_dialogflow /us
sudo sed -i -r -e 's/(.*AM_CFLAGS\))/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am
sudo sed -i -r -e 's/(.*-std=c++11)/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am
# copy Makefiles into place
# copy Makefiles and patches into place
cp /tmp/configure.ac.extra /usr/local/src/freeswitch/configure.ac
cp /tmp/Makefile.am.extra /usr/local/src/freeswitch/Makefile.am
cp /tmp/modules.conf.in.extra /usr/local/src/freeswitch/build/modules.conf.in
@@ -82,13 +82,16 @@ cp /tmp/avmd.conf.xml /usr/local/src/freeswitch/conf/vanilla/autoload_configs/av
cp /tmp/switch_rtp.c.patch /usr/local/src/freeswitch/src
cp /tmp/switch_core_media.c.patch /usr/local/src/freeswitch/src
cp /tmp/mod_avmd.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_avmd
cp /tmp/mod_httapi.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_httapi
# patch freeswitch
cd /usr/local/src/freeswitch/src
patch < switch_rtp.c.patch
patch < switch_core_media.c.patch
cd mod/applications/mod_avmd
cd /usr/local/src/freeswitch/src/mod/applications/mod_avmd
patch < mod_avmd.c.patch
cd /usr/local/src/freeswitch/src/mod/applications/mod_httapi
patch < mod_httapi.c.patch
# build libwebsockets
cd /usr/local/src/libwebsockets