aboutsummaryrefslogtreecommitdiff
path: root/samples/SpeechRecognition/test/DecoderTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'samples/SpeechRecognition/test/DecoderTest.cpp')
-rw-r--r--samples/SpeechRecognition/test/DecoderTest.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/samples/SpeechRecognition/test/DecoderTest.cpp b/samples/SpeechRecognition/test/DecoderTest.cpp
new file mode 100644
index 0000000000..13a3905b99
--- /dev/null
+++ b/samples/SpeechRecognition/test/DecoderTest.cpp
@@ -0,0 +1,86 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <catch.hpp>
+#include <map>
+#include "Decoder.hpp"
+
+std::map<int, std::string> labels = {
+ {0, "a" },
+ {1, "b" },
+ {2, "c" },
+ {3, "d" },
+ {4, "e" },
+ {5, "f" },
+ {6, "g" },
+ {7, "h" },
+ {8, "i" },
+ {9, "j" },
+ {10,"k" },
+ {11,"l" },
+ {12,"m" },
+ {13,"n" },
+ {14,"o" },
+ {15,"p" },
+ {16,"q" },
+ {17,"r" },
+ {18,"s" },
+ {19,"t" },
+ {20,"u" },
+ {21,"v" },
+ {22,"w" },
+ {23,"x" },
+ {24,"y" },
+ {25,"z" },
+ {26, "\'" },
+ {27, " "},
+ {28,"$" }
+};
+
+TEST_CASE("Test Wav2Letter output decoder")
+{
+
+ std::vector<uint16_t> outputValues =
+ {
+ 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1,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decoder.DecodeOutput<int8_t>(convertedValues);
+ CHECK(text == "hello");
+}
+
+