aboutsummaryrefslogtreecommitdiff
path: root/samples/SpeechRecognition/test/AudioCaptureTest.cpp
diff options
context:
space:
mode:
authorÉanna Ó Catháin <eanna.ocathain@arm.com>2021-04-07 14:35:25 +0100
committerJim Flynn <jim.flynn@arm.com>2021-05-07 09:11:52 +0000
commitc6ab02a626e15b4a12fc09ecd844eb8b95380c3c (patch)
tree9912ed9cdb89cdb24483b22d6621ae30049ae321 /samples/SpeechRecognition/test/AudioCaptureTest.cpp
parente813d67f86df41a238ff79b5c554ef5027f56576 (diff)
downloadarmnn-c6ab02a626e15b4a12fc09ecd844eb8b95380c3c.tar.gz
MLECO-1252 ASR sample application using the public ArmNN C++ API.
Change-Id: I98cd505b8772a8c8fa88308121bc94135bb45068 Signed-off-by: Éanna Ó Catháin <eanna.ocathain@arm.com>
Diffstat (limited to 'samples/SpeechRecognition/test/AudioCaptureTest.cpp')
-rw-r--r--samples/SpeechRecognition/test/AudioCaptureTest.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/samples/SpeechRecognition/test/AudioCaptureTest.cpp b/samples/SpeechRecognition/test/AudioCaptureTest.cpp
new file mode 100644
index 0000000000..94b4e7cb7a
--- /dev/null
+++ b/samples/SpeechRecognition/test/AudioCaptureTest.cpp
@@ -0,0 +1,61 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#define CATCH_CONFIG_MAIN
+#include <catch.hpp>
+#include <limits>
+
+#include "AudioCapture.hpp"
+
+TEST_CASE("Test capture of audio file")
+{
+ std::string testResources = TEST_RESOURCE_DIR;
+ REQUIRE(testResources != "");
+ std::string file = testResources + "/" + "myVoiceIsMyPassportVerifyMe04.wav";
+ asr::AudioCapture capture;
+ std::vector<float> audioData = capture.LoadAudioFile(file);
+ capture.InitSlidingWindow(audioData.data(), audioData.size(), 47712, 16000);
+
+ std::vector<float> firstAudioBlock = capture.Next();
+ float actual1 = firstAudioBlock.at(0);
+ float actual2 = firstAudioBlock.at(47000);
+ CHECK(std::to_string(actual1) == "0.000352");
+ CHECK(std::to_string(actual2) == "-0.056441");
+ CHECK(firstAudioBlock.size() == 47712);
+
+ CHECK(capture.HasNext() == true);
+
+ std::vector<float> secondAudioBlock = capture.Next();
+ float actual3 = secondAudioBlock.at(0);
+ float actual4 = secondAudioBlock.at(47000);
+ CHECK(std::to_string(actual3) == "0.102077");
+ CHECK(std::to_string(actual4) == "0.000194");
+ CHECK(capture.HasNext() == true);
+
+ std::vector<float> thirdAudioBlock = capture.Next();
+ float actual5 = thirdAudioBlock.at(0);
+ float actual6 = thirdAudioBlock.at(33500);
+ float actual7 = thirdAudioBlock.at(33600);
+ CHECK(std::to_string(actual5) == "-0.076416");
+ CHECK(std::to_string(actual6) == "-0.000275");
+ CHECK(std::to_string(actual7) == "0.000000");
+ CHECK(capture.HasNext() == false);
+}
+
+TEST_CASE("Test sliding window of audio capture")
+{
+ std::string testResources = TEST_RESOURCE_DIR;
+ REQUIRE(testResources != "");
+ std::string file = testResources + "/" + "myVoiceIsMyPassportVerifyMe04.wav";
+ asr::AudioCapture capture;
+ std::vector<float> audioData = capture.LoadAudioFile(file);
+ capture.InitSlidingWindow(audioData.data(), audioData.size(), 47712, 16000);
+ capture.Next();
+ capture.Next();
+
+ CHECK(capture.HasNext() == true);
+ capture.Next();
+ CHECK(capture.HasNext() == false);
+}