C# Integration recording problem
See original GitHub issueHi, I’m trying to run the .NET demo, and I’m running into some problems.
I’m getting the following exception:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
StackTrace:
at Arthur.WindowsClient.Services.Porcupine.pv_porcupine_process(IntPtr pointer, Int16[] voiceData, Boolean& results)
at Arthur.WindowsClient.Services.Porcupine.Process(Int16[] data, Boolean& result) in path\to\file\Services\Porcupine.cs:line 106
at Arthur.WindowsClient.Services.HotWordDetection.Start() in path\to\file\Services\HotWordDetection.cs:line 52
at Arthur.WindowsClient.ConsoleAppTest.Program.Main() in path\to\file\ConsoleAppTest\Program.cs:line 50
Steps to reproduce the behavior
I’ve set the build action to Any CPU
This is my code:
public class HotWordDetection
{
private short[] GetNextAudioFrame()
{
if (WaveIn.DeviceCount < 1)
{
Console.WriteLine("No microphone!");
}
// some functionality that gets the next frame
var waveIn = new WaveInEvent
{
DeviceNumber = 0,
WaveFormat = new WaveFormat(16000, 1)
};
var writeLock = new object();
byte[] data = new byte[8192];
waveIn.DataAvailable += (sender, args) =>
{
lock (writeLock)
{
Buffer.BlockCopy(args.Buffer, 0, data, 0, args.BytesRecorded);
}
};
waveIn.StartRecording();
Console.WriteLine("Listening...");
//Task.Delay(TimeSpan.FromSeconds(3));
Thread.Sleep(3000);
waveIn.StopRecording();
List<short> frames = new List<short>();
foreach (var value in data)
{
frames.Add(value);
}
return frames.ToArray();
}
public void Start()
{
string modelFilePath = @"path\to\file\porcupine_params.pv";
float sensitivity = (float)0.5;
string keyword_file_path = @"path\to\file\alexa_windows.ppn";
Porcupine instance = new Porcupine(modelFilePath, keyword_file_path, sensitivity);
int i = 0;
while (true)
{
Console.WriteLine(i++);
var frame = GetNextAudioFrame();
var status = instance.Process(frame, out var result);
if (status != PicoVoiceStatus.SUCCESS)
{
// error handling logic
}
if (result)
{
// detection event logic/callback
Console.WriteLine("SUCCESS");
Thread.Sleep(5000);
}
}
}
}
This happens after 79 iterations of the while loop. I believe it might be a problem with the recording. I would appreciate it very much if you could help me with this issue.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Configure and Troubleshoot Basic Call Recording - Cisco
This document describes the basics of call recording within Cisco Unified Communications Manager (CUCM).
Read more >Record steps to reproduce a problem - Microsoft Support
Steps Recorder (called Problems Steps Recorder in Windows 7), is a program that helps you troubleshoot a problem on your device by recording...
Read more >LiveRecorder Time Travel Debugging for C/C++ ¦ Undo
LiveRecorder is a powerful time travel debugging platform that enables developers to understand code execution and fix bugs faster. Record. Replay. Resolve.
Read more >х WEBCAM RECORDING 2 DETAILS SCALCET9M 5.5.044 ...
Question : х WEBCAM RECORDING 2 DETAILS SCALCET9M 5.5.044. Evoluate the indefinite integral. (Use C for the constant of integration.) cos (t) V2...
Read more >Session Recording 2209 - Carl Stalhood
Create a DNS host record that resolves to the Load Balancing VIP and matches the certificate bound to the vServer. Go to C:\Windows\System32\ ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @laves !
I see. I should have done my research better. I will try your approach (using OpenAL.dll) and report any findings/resolutions on the problems you encountered.
Thank you so much for your input and your time.
Cheers!
Hi @koskit,
Thanks for your interest in Porcupine - seems like you did a lot of good work here! I’m the developer who implemented the .NET SDK and worked on the demos. We were very interested in getting .NET Core running on Raspbian at the time of implementation, but had to move on to other SDKs before we could get a dependable version running.
The main issue with running on the rpi was to do with loading the correct Porcupine library file for the specific ARM architecture of rpi the developer is using. We use DllImport to load the Porcupine library in our SDK and it has a limitation with respect to detecting the proper architecture. When running on a Linux system it will just grab the first libpv_porcupine.so it finds and not select based on architecture. We could solve this with the NativeLibrary class and some additional platform detection logic, but it would restrict our support to .NET Core 3.0+ and we were trying to keep .NET Framework devs happy. We will eventually move in this direction if there’s enough interest since .NET Framework is coming up on end-of-support in the next few years.
The other issue you may encounter has to do with NAudio. We initially used NAudio in our demos, but found that it doesn’t support cross-platform audio input. Unfortunately, as it stands, NAudio’s audio recording capabilities are restricted to Windows, though they do support file reading and the like on other OSs. The reason we moved to OpenAL is because of it’s audio input support on Windows, macOS and Linux. If you want your application to run on Raspbian, you would not be able to use NAudio, so you may want to consider either restricting to Windows IoT Core or finding a way of integrating OpenAL into your application. It may work if you just include the OpenAL .dll and .so with your application.
All that said, these are not issues that should prevent you from making Porcupine work for you! I just wanted to make you aware of .NET Core limitations we encountered while implementing the SDK and demos. If you can overcome any of these limitations we’d love to hear about it and open a feature request for it as IoT Core and Raspbian are definitely OSs we’d love to support with our .NET SDK.
ps - if you use static
create
constructor you can make Porcupine with simplyPorcupine.Create(keywords:Porcupine.KEYWORDS)
and it will fill in the modelPath, sensitivities and keywordPaths for you!