blob: 41fbe07636707e388c523d909c2b1df6deac9547 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * 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 */
17#include "OutputDecode.hpp"
18
19namespace arm {
20namespace app {
21namespace audio {
22namespace asr {
23
24 std::string DecodeOutput(const std::vector<ClassificationResult>& vecResults)
25 {
26 std::string CleanOutputBuffer;
27
28 for (size_t i = 0; i < vecResults.size(); ++i) /* For all elements in vector. */
29 {
30 while (i+1 < vecResults.size() &&
31 vecResults[i].m_label == vecResults[i+1].m_label) /* While the current element is equal to the next, ignore it and move on. */
32 {
33 ++i;
34 }
35 if (vecResults[i].m_label != "$") /* $ is a character used to represent unknown and double characters so should not be in output. */
36 {
37 CleanOutputBuffer += vecResults[i].m_label; /* If the element is different to the next, it will be appended to CleanOutputBuffer. */
38 }
39 }
40
41 return CleanOutputBuffer; /* Return string type containing clean output. */
42 }
43
44} /* namespace asr */
45} /* namespace audio */
46} /* namespace app */
47} /* namespace arm */