aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/examples/keyword_spotting/audio_utils.py
diff options
context:
space:
mode:
authoralexander <alexander.efremov@arm.com>2021-07-16 11:30:56 +0100
committerJim Flynn <jim.flynn@arm.com>2022-02-04 09:55:21 +0000
commitf42f56870c6201a876f025a423eb5540d7438e83 (patch)
treee8e57e371c851cbb9a51a2f3ec35059addd2e93e /python/pyarmnn/examples/keyword_spotting/audio_utils.py
parent9d74ba6e85a043e9603445e062315f5c4965fbd6 (diff)
downloadarmnn-f42f56870c6201a876f025a423eb5540d7438e83.tar.gz
MLECO-2079 Adding the python KWS example
Signed-off-by: Eanna O Cathain <eanna.ocathain@arm.com> Change-Id: Ie1463aaeb5e3cade22df8f560ae99a8e1c4a9c17
Diffstat (limited to 'python/pyarmnn/examples/keyword_spotting/audio_utils.py')
-rw-r--r--python/pyarmnn/examples/keyword_spotting/audio_utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python/pyarmnn/examples/keyword_spotting/audio_utils.py b/python/pyarmnn/examples/keyword_spotting/audio_utils.py
new file mode 100644
index 0000000000..723c0e38f6
--- /dev/null
+++ b/python/pyarmnn/examples/keyword_spotting/audio_utils.py
@@ -0,0 +1,31 @@
+# Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+# SPDX-License-Identifier: MIT
+
+"""Utilities for speech recognition apps."""
+
+import numpy as np
+
+
+def decode(model_output: np.ndarray, labels: dict) -> list:
+ """Decodes the integer encoded results from inference into a string.
+
+ Args:
+ model_output: Results from running inference.
+ labels: Dictionary of labels keyed on the classification index.
+
+ Returns:
+ Decoded string.
+ """
+ results = [labels[np.argmax(model_output)], model_output[0][0][np.argmax(model_output)]]
+
+ return results
+
+
+def display_text(text: list):
+ """Presents the results on the console.
+
+ Args:
+ text: Results of performing ASR on the input audio data.
+ """
+ print('Classification: %s' % text[0])
+ print('Probability: %s' % text[1])