1# Copyright © 2021 Arm Ltd and Contributors. All rights reserved. 2# SPDX-License-Identifier: MIT 3 4"""Utilities for speech recognition apps.""" 5 6import numpy as np 7 8 9def decode(model_output: np.ndarray, labels: dict) -> list: 10 """Decodes the integer encoded results from inference into a string. 11 12 Args: 13 model_output: Results from running inference. 14 labels: Dictionary of labels keyed on the classification index. 15 16 Returns: 17 Decoded string. 18 """ 19 results = [labels[np.argmax(model_output)], model_output[0][0][np.argmax(model_output)]] 20 21 return results 22 23 24def display_text(text: list): 25 """Presents the results on the console. 26 27 Args: 28 text: Results of performing ASR on the input audio data. 29 """ 30 print('Classification: %s' % text[0]) 31 print('Probability: %s' % text[1]) 32