blob: 59ef4509caca1038b8274163c0f360f66fef56ed [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
Richard Burton4e002792022-05-04 09:45:02 +01002# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
alexander3c798932021-03-26 21:42:19 +00003# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010017# Append the APIs to use for this use case
18list(APPEND ${use_case}_API_LIST "kws" "asr")
alexander3c798932021-03-26 21:42:19 +000019
alexander3c798932021-03-26 21:42:19 +000020USER_OPTION(${use_case}_FILE_PATH "Directory with WAV files, or path to a single WAV file, to use in the evaluation application."
21 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/samples/
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010022 PATH_OR_FILE)
alexander3c798932021-03-26 21:42:19 +000023
24USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000."
25 16000
26 STRING)
27
28USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON."
29 ON
30 BOOL)
31
32USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0."
33 0
34 STRING)
35
36USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed."
37 0
38 STRING)
39
40USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'."
41 kaiser_best
42 STRING)
43
44USER_OPTION(${use_case}_AUDIO_MIN_SAMPLES "Specify the minimum number of samples to use. By default is 16000, if the audio is shorter will be automatically padded."
45 16000
46 STRING)
47
alexander3c798932021-03-26 21:42:19 +000048# Generate kws labels file:
49USER_OPTION(${use_case}_LABELS_TXT_FILE_KWS "Labels' txt file for the chosen model."
Kshitij Sisodia76a15802021-12-24 11:05:11 +000050 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/micronet_kws_labels.txt
alexander3c798932021-03-26 21:42:19 +000051 FILEPATH)
52
alexander3c798932021-03-26 21:42:19 +000053# Generate asr labels file:
54USER_OPTION(${use_case}_LABELS_TXT_FILE_ASR "Labels' txt file for the chosen model."
55 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/labels_wav2letter.txt
56 FILEPATH)
57
alexander3c798932021-03-26 21:42:19 +000058
59USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
Kshitij Sisodia661959c2021-11-24 10:39:52 +000060 0x00200000
alexander3c798932021-03-26 21:42:19 +000061 STRING)
62
63USER_OPTION(${use_case}_MODEL_SCORE_THRESHOLD_KWS "Specify the score threshold [0.0, 1.0) that must be applied to the KWS results for a label to be deemed valid."
Richard Burton4e002792022-05-04 09:45:02 +010064 0.7
alexander3c798932021-03-26 21:42:19 +000065 STRING)
66
67USER_OPTION(${use_case}_MODEL_SCORE_THRESHOLD_ASR "Specify the score threshold [0.0, 1.0) that must be applied to the ASR results for a label to be deemed valid."
68 0.5
69 STRING)
70
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010071if (ETHOS_U_NPU_ENABLED)
Kshitij Sisodia76a15802021-12-24 11:05:11 +000072 set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/kws_micronet_m_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite)
Kshitij Sisodia3be26232021-10-29 12:29:06 +010073 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite)
alexander3c798932021-03-26 21:42:19 +000074else()
Kshitij Sisodia76a15802021-12-24 11:05:11 +000075 set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/kws_micronet_m.tflite)
Kshitij Sisodiae12ac832021-05-20 11:18:53 +010076 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8.tflite)
alexander3c798932021-03-26 21:42:19 +000077endif()
78
alexander3c798932021-03-26 21:42:19 +000079USER_OPTION(${use_case}_MODEL_TFLITE_PATH_KWS "NN models file to be used for KWS in the evaluation application. Model files must be in tflite format."
80 ${DEFAULT_MODEL_PATH_KWS}
81 FILEPATH
82 )
83
84USER_OPTION(${use_case}_MODEL_TFLITE_PATH_ASR "NN models file to be used for ASR in the evaluation application. Model files must be in tflite format."
85 ${DEFAULT_MODEL_PATH_ASR}
86 FILEPATH
87 )
88
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010089# If the target platform is native
90if (${TARGET_PLATFORM} STREQUAL native)
91 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR}/asr ${DEFAULT_TEST_DATA_DIR}/kws)
92endif()
93
94set(EXTRA_MODEL_CODE_KWS
95 "/* Model parameters for ${use_case} */"
96 "extern const uint32_t g_NumMfcc = 10"
97 "extern const uint32_t g_NumAudioWins = 49"
98 "extern const int g_FrameLength = 640"
99 "extern const int g_FrameStride = 320"
100 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_KWS}"
101 )
102
103set(EXTRA_MODEL_CODE_ASR
104 "/* Model parameters for ${use_case} */"
105 "extern const int g_FrameLength = 512"
106 "extern const int g_FrameStride = 160"
107 "extern const int g_ctxLen = 98"
108 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_ASR}"
109 )
110
alexander3c798932021-03-26 21:42:19 +0000111# Generate model file for KWS
112generate_tflite_code(
113 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_KWS}
114 DESTINATION ${SRC_GEN_DIR}
115 EXPRESSIONS ${EXTRA_MODEL_CODE_KWS}
116 NAMESPACE "arm" "app" "kws"
117)
118
119# and for ASR
120generate_tflite_code(
121 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_ASR}
122 DESTINATION ${SRC_GEN_DIR}
123 EXPRESSIONS ${EXTRA_MODEL_CODE_ASR}
124 NAMESPACE "arm" "app" "asr"
125)
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100126
127generate_labels_code(
128 INPUT "${${use_case}_LABELS_TXT_FILE_ASR}"
129 DESTINATION_SRC ${SRC_GEN_DIR}
130 DESTINATION_HDR ${INC_GEN_DIR}
131 OUTPUT_FILENAME "Labels_wav2letter"
132 NAMESPACE "arm" "app" "asr"
133)
134
135generate_labels_code(
136 INPUT "${${use_case}_LABELS_TXT_FILE_KWS}"
137 DESTINATION_SRC ${SRC_GEN_DIR}
138 DESTINATION_HDR ${INC_GEN_DIR}
Kshitij Sisodia76a15802021-12-24 11:05:11 +0000139 OUTPUT_FILENAME "Labels_micronetkws"
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100140 NAMESPACE "arm" "app" "kws"
141)
142
143# Generate audio .cc files:
144generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR}
145 ${${use_case}_AUDIO_RATE}
146 ${${use_case}_AUDIO_MONO}
147 ${${use_case}_AUDIO_OFFSET}
148 ${${use_case}_AUDIO_DURATION}
149 ${${use_case}_AUDIO_RES_TYPE}
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100150 ${${use_case}_AUDIO_MIN_SAMPLES})