aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/examples/keyword_spotting/audio_utils.py
blob: 723c0e38f6dde0320040cb557b45a67460c291f8 (plain)
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
# 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])