New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to continuously record audio using OpenAL? #1696
Comments
It's unclear here what the actual problem is here. What is the code above do when run? What do you expect to happen and what actually happens? |
When I send the audio to the transcriber engine it should return me with partial transcripts, but currently, it is stuck on line |
Ok so I'm seeing a few issues. One is that you are not waiting for new samples to become available, you are reading them as fast as you can so most of the time you are only getting a few samples. Another issue is that you are writing to the same part of the buffer every time. Something not part of the code you are showing that could cause a potential issue is how you are handling OpenAL contexts (I don't remember if you need a context to record audio). A context is thread specific so running from a task could need you to make the context current from within the task. |
Sorry for the delay. Thank you for your feedback. I am now getting transcripts back, although less accurate than usual. I'd say 20% less accurate than I'm used to. This is what the code looks like now: const int sampleRate = 16_000;
const int bufferSize = 1024;
var captureDevice = ALC.CaptureOpenDevice(null, sampleRate, ALFormat.Mono16, bufferSize);
ALC.CaptureStart(captureDevice);
var buffer = new byte[bufferSize];
while (true)
{
var current = 0;
while (current < buffer.Length && !ct.IsCancellationRequested)
{
var samplesAvailable = ALC.GetInteger(captureDevice, AlcGetInteger.CaptureSamples);
if (samplesAvailable < 512) continue;
var samplesToRead = Math.Min(samplesAvailable, buffer.Length - current);
ALC.CaptureSamples(captureDevice, ref buffer[current], samplesToRead);
current += samplesToRead;
}
if (ct.IsCancellationRequested) break;
// copy buffer so that it can be used in another thread
transcribeAudio(buffer.ToArray());
} This code is running in an async function, another async function cancels the cancellation token when a key is pressed. |
I'm also frequently getting this error: |
Any updates on this issue? |
Unfortunately, I didn't get anywhere after this roadblock. It mostly works, but crashes after a short period, between 30s to multiple minutes. |
Description
I'm not too familiar with OpenAL and audio in general, so I'm a little out of my depth here.
I'm trying to capture continuous audio from a microphone using .NET across Windows/Mac/Linux.
I looked at ALTest and tried to modify it to continuously listen to audio, but I don't know how I should modify it for that purpose.
I also found a lot of the examples online using the
AudioCapture
class, but it isn't included in the NuGet package.Here's what I got:
Inside of
processBuffer
I'm sending the audio to a transcription engine.Related information
If you could point me to a good resource, that'd be greatly appreciated! 🙇
The text was updated successfully, but these errors were encountered: