Skip to content

Commit

Permalink
minor refactor for csharp binding test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenarsa committed Feb 16, 2020
1 parent 6f339a8 commit a327cd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2,165 deletions.
16 changes: 8 additions & 8 deletions binding/dotnet/PorcupineTest/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ public void TestProcess()

Assert.IsTrue(File.Exists(modelFilePath), $"File.Exists(modelFilePath) --> {modelFilePath}");
keywordPaths.ForEach(keywordFilePath => Assert.IsTrue(File.Exists(keywordFilePath), $"File.Exists(keywordFilePath) --> {keywordFilePath}"));
Console.WriteLine(keywordPaths);
Porcupine p = new Porcupine(modelFilePath, keywordPaths: keywordPaths, sensitivities: sensitivities);
WAVFile file = new WAVFile();
file.Open("multiple_keywords.wav", WAVFile.WAVFileMode.READ);
Assert.AreEqual(p.SampleRate(), file.AudioFormat.SampleRateHz, "The samplerate is not equal!!!");

List<short> data = new List<short>();
while (file.NumSamplesRemaining > 0)
{
data.Add(BitConverter.ToInt16(file.GetNextSample_ByteArray()));
using (BinaryReader reader = new BinaryReader(File.Open("multiple_keywords.wav", FileMode.Open))) {
reader.ReadBytes(44);

while (reader.BaseStream.Position != reader.BaseStream.Length) {
data.Add(reader.ReadInt16());
}
}

int framecount = (int)Math.Floor((decimal)(data.Count / p.FrameLength()));
var results = new List<int>();
for (int i = 0; i < framecount; i++)
Expand All @@ -77,7 +78,6 @@ public void TestProcess()
if (result >= 0)
{
results.Add(result);
Console.WriteLine(result);
}
}

Expand Down
Loading

0 comments on commit a327cd8

Please sign in to comment.