File size: 3,938 Bytes
759d0dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TARGET="${AXERA_TARGET:-AX650}"
AUDIO_DIR="${AUDIO_DIR:-${ROOT}/audio/openwakeword}"
THRESHOLD="${THRESHOLD:-0.5}"
case "${TARGET}" in
AX650)
TARGET_SLUG="ax650"
BINARY="${ROOT}/cpp/bin/openwakeword_ax650"
MODELS_DIR="${MODELS_DIR:-${ROOT}/models/650}"
BSP_LIB_DIR="${AXERA_BSP_LIB_DIR:-${AX650_BSP_LIB_DIR:-${ROOT}/cpp/toolchains/ax650n_bsp_sdk/msp/out/lib}}"
BUILD_SCRIPT="cpp/build_ax650.sh"
;;
AX630C)
TARGET_SLUG="ax630c"
BINARY="${ROOT}/cpp/bin/openwakeword_ax630c"
MODELS_DIR="${MODELS_DIR:-${ROOT}/models/630C}"
BSP_LIB_DIR="${AXERA_BSP_LIB_DIR:-${AX630C_BSP_LIB_DIR:-${ROOT}/cpp/toolchains/ax620e_bsp_sdk/msp/out/arm64_glibc/lib}}"
BUILD_SCRIPT="cpp/build_ax630c.sh"
;;
*)
echo "ERROR: AXERA_TARGET must be AX650 or AX630C" >&2
exit 2
;;
esac
OUTPUT_DIR="${OUTPUT_DIR:-${ROOT}/outputs/cpp_${TARGET_SLUG}_batch}"
if [[ ! -x "${BINARY}" ]]; then
echo "ERROR: ${BINARY} is missing; run bash ${BUILD_SCRIPT} first" >&2
exit 2
fi
if [[ ! -d "${AUDIO_DIR}" ]]; then
echo "ERROR: audio directory does not exist: ${AUDIO_DIR}" >&2
exit 2
fi
for name in embedding_model alexa_v0.1 hey_jarvis_v0.1 hey_mycroft_v0.1 \
hey_rhasspy_v0.1 timer_v0.1 weather_v0.1; do
model="${MODELS_DIR}/openwakeword__${name}.axmodel"
if [[ ! -f "${model}" ]]; then
echo "ERROR: ${TARGET} model is missing: ${model}" >&2
exit 2
fi
done
mapfile -d '' AUDIO_FILES < <(
find "${AUDIO_DIR}" -maxdepth 1 -type f -iname '*.wav' -print0 | sort -z
)
if [[ "${#AUDIO_FILES[@]}" -eq 0 ]]; then
echo "ERROR: no WAV files found under ${AUDIO_DIR}" >&2
exit 2
fi
mkdir -p "${OUTPUT_DIR}/logs"
RESULTS="${OUTPUT_DIR}/results.tsv"
SUMMARY="${OUTPUT_DIR}/summary.txt"
printf 'file\taudio_seconds\tfeature_seconds\tnpu_seconds\tinference_seconds\trtf\tmodel_load_seconds\tdetections\n' > "${RESULTS}"
export LD_LIBRARY_PATH="${BSP_LIB_DIR}:${LD_LIBRARY_PATH:-}"
for audio in "${AUDIO_FILES[@]}"; do
name="$(basename "${audio}")"
stem="${name%.*}"
log="${OUTPUT_DIR}/logs/${stem}.log"
echo "[RUN] target=${TARGET} ${name} threshold=${THRESHOLD}"
"${BINARY}" \
--models-dir "${MODELS_DIR}" \
--mel-weights "${ROOT}/config/openwakeword_mel_weights.bin" \
--audio "${audio}" \
--threshold "${THRESHOLD}" > "${log}" 2>&1
cat "${log}"
field() {
awk -F': ' -v key="$1" '$1 == key {print $2; exit}' "${log}"
}
audio_seconds="$(field audio_seconds)"
feature_seconds="$(field feature_seconds)"
npu_seconds="$(field npu_seconds)"
inference_seconds="$(field inference_seconds)"
rtf="$(field rtf)"
model_load_seconds="$(field model_load_seconds)"
detections="$(awk '$NF == "WAKEUP" {print $1}' "${log}" | paste -sd ',' -)"
detections="${detections:-none}"
for value in "${audio_seconds}" "${feature_seconds}" "${npu_seconds}" \
"${inference_seconds}" "${rtf}" "${model_load_seconds}"; do
if [[ -z "${value}" ]]; then
echo "ERROR: timing field missing from ${log}" >&2
exit 1
fi
done
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' \
"${name}" "${audio_seconds}" "${feature_seconds}" "${npu_seconds}" \
"${inference_seconds}" "${rtf}" "${model_load_seconds}" "${detections}" \
>> "${RESULTS}"
done
awk -F'\t' '
NR > 1 {
files += 1
audio += $2
feature += $3
npu += $4
inference += $5
model_load += $7
}
END {
printf "files: %d\n", files
printf "total_audio_seconds: %.6f\n", audio
printf "total_feature_seconds: %.6f\n", feature
printf "total_npu_seconds: %.6f\n", npu
printf "total_inference_seconds: %.6f\n", inference
printf "total_model_load_seconds: %.6f\n", model_load
printf "rtf: %.6f\n", inference / audio
}
' "${RESULTS}" > "${SUMMARY}"
echo "[SUMMARY]"
cat "${SUMMARY}"
echo "results: ${RESULTS}"
echo "logs: ${OUTPUT_DIR}/logs"
|