blob: de84bfd9057714f4090e656e458ad26fa8db3348 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
Richard Burtonf32a86a2022-11-15 11:46:11 +00002# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
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
Eanna O Cathain4c0ac912022-09-22 15:18:34 +010020set_input_file_path_user_option(".wav" ${use_case})
alexander3c798932021-03-26 21:42:19 +000021
22USER_OPTION(${use_case}_AUDIO_RATE "Specify the target sampling rate. Default is 16000."
23 16000
24 STRING)
25
26USER_OPTION(${use_case}_AUDIO_MONO "Specify if the audio needs to be converted to mono. Default is ON."
27 ON
28 BOOL)
29
30USER_OPTION(${use_case}_AUDIO_OFFSET "Specify the offset to start reading after this time (in seconds). Default is 0."
31 0
32 STRING)
33
34USER_OPTION(${use_case}_AUDIO_DURATION "Specify the audio duration to load (in seconds). If set to 0 the entire audio will be processed."
35 0
36 STRING)
37
38USER_OPTION(${use_case}_AUDIO_RES_TYPE "Specify re-sampling algorithm to use. By default is 'kaiser_best'."
39 kaiser_best
40 STRING)
41
42USER_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."
43 16000
44 STRING)
45
alexander3c798932021-03-26 21:42:19 +000046# Generate kws labels file:
47USER_OPTION(${use_case}_LABELS_TXT_FILE_KWS "Labels' txt file for the chosen model."
Kshitij Sisodia76a15802021-12-24 11:05:11 +000048 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/micronet_kws_labels.txt
alexander3c798932021-03-26 21:42:19 +000049 FILEPATH)
50
alexander3c798932021-03-26 21:42:19 +000051# Generate asr labels file:
52USER_OPTION(${use_case}_LABELS_TXT_FILE_ASR "Labels' txt file for the chosen model."
53 ${CMAKE_CURRENT_SOURCE_DIR}/resources/${use_case}/labels/labels_wav2letter.txt
54 FILEPATH)
55
alexander3c798932021-03-26 21:42:19 +000056
57USER_OPTION(${use_case}_ACTIVATION_BUF_SZ "Activation buffer size for the chosen model"
Kshitij Sisodia661959c2021-11-24 10:39:52 +000058 0x00200000
alexander3c798932021-03-26 21:42:19 +000059 STRING)
60
61USER_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 +010062 0.7
alexander3c798932021-03-26 21:42:19 +000063 STRING)
64
65USER_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."
66 0.5
67 STRING)
68
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010069if (ETHOS_U_NPU_ENABLED)
Kshitij Sisodia76a15802021-12-24 11:05:11 +000070 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 +010071 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8_vela_${ETHOS_U_NPU_CONFIG_ID}.tflite)
alexander3c798932021-03-26 21:42:19 +000072else()
Kshitij Sisodia76a15802021-12-24 11:05:11 +000073 set(DEFAULT_MODEL_PATH_KWS ${DEFAULT_MODEL_DIR}/kws_micronet_m.tflite)
Kshitij Sisodiae12ac832021-05-20 11:18:53 +010074 set(DEFAULT_MODEL_PATH_ASR ${DEFAULT_MODEL_DIR}/wav2letter_pruned_int8.tflite)
alexander3c798932021-03-26 21:42:19 +000075endif()
76
alexander3c798932021-03-26 21:42:19 +000077USER_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."
78 ${DEFAULT_MODEL_PATH_KWS}
79 FILEPATH
80 )
81
82USER_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."
83 ${DEFAULT_MODEL_PATH_ASR}
84 FILEPATH
85 )
86
Isabella Gottardi2181d0a2021-04-07 09:27:38 +010087# If the target platform is native
88if (${TARGET_PLATFORM} STREQUAL native)
89 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR}/asr ${DEFAULT_TEST_DATA_DIR}/kws)
90endif()
91
92set(EXTRA_MODEL_CODE_KWS
93 "/* Model parameters for ${use_case} */"
94 "extern const uint32_t g_NumMfcc = 10"
95 "extern const uint32_t g_NumAudioWins = 49"
96 "extern const int g_FrameLength = 640"
97 "extern const int g_FrameStride = 320"
98 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_KWS}"
99 )
100
101set(EXTRA_MODEL_CODE_ASR
102 "/* Model parameters for ${use_case} */"
103 "extern const int g_FrameLength = 512"
104 "extern const int g_FrameStride = 160"
105 "extern const int g_ctxLen = 98"
106 "extern const float g_ScoreThreshold = ${${use_case}_MODEL_SCORE_THRESHOLD_ASR}"
107 )
108
alexander3c798932021-03-26 21:42:19 +0000109# Generate model file for KWS
110generate_tflite_code(
111 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_KWS}
112 DESTINATION ${SRC_GEN_DIR}
113 EXPRESSIONS ${EXTRA_MODEL_CODE_KWS}
114 NAMESPACE "arm" "app" "kws"
115)
116
117# and for ASR
118generate_tflite_code(
119 MODEL_PATH ${${use_case}_MODEL_TFLITE_PATH_ASR}
120 DESTINATION ${SRC_GEN_DIR}
121 EXPRESSIONS ${EXTRA_MODEL_CODE_ASR}
122 NAMESPACE "arm" "app" "asr"
123)
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100124
125generate_labels_code(
126 INPUT "${${use_case}_LABELS_TXT_FILE_ASR}"
127 DESTINATION_SRC ${SRC_GEN_DIR}
128 DESTINATION_HDR ${INC_GEN_DIR}
129 OUTPUT_FILENAME "Labels_wav2letter"
130 NAMESPACE "arm" "app" "asr"
131)
132
133generate_labels_code(
134 INPUT "${${use_case}_LABELS_TXT_FILE_KWS}"
135 DESTINATION_SRC ${SRC_GEN_DIR}
136 DESTINATION_HDR ${INC_GEN_DIR}
Kshitij Sisodia76a15802021-12-24 11:05:11 +0000137 OUTPUT_FILENAME "Labels_micronetkws"
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100138 NAMESPACE "arm" "app" "kws"
139)
140
141# Generate audio .cc files:
142generate_audio_code(${${use_case}_FILE_PATH} ${SRC_GEN_DIR} ${INC_GEN_DIR}
143 ${${use_case}_AUDIO_RATE}
144 ${${use_case}_AUDIO_MONO}
145 ${${use_case}_AUDIO_OFFSET}
146 ${${use_case}_AUDIO_DURATION}
147 ${${use_case}_AUDIO_RES_TYPE}
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100148 ${${use_case}_AUDIO_MIN_SAMPLES})