Comments (14)
Might be worth looking at WasapiCapture
now that it supports built-in resampling in NAudio 2.1.0
from naudio.
Not seen this myself. You might want to try WaveInEvent
instead
from naudio.
@markheath, did you tried my test program with 1.7.3 version or newer?
from naudio.
sorry, haven't had a chance to try this myself. However, if I had an application that needed to stop and start recording frequently with small gaps, I would actually not use StopRecording
and StartRecording
. Instead I would just have a boolean flag saying whether I was currently recording and in my DataAvailable
event I'd just ignore it if my flag wasn't set
from naudio.
that needed to stop and start recording frequently with small gaps
Gaps are small in this test program because it is easier to reproduce the problem in such way.
Instead I would just have a boolean flag
I was thinking about solution with data discarding, but it have some problems:
- It uses more system resources that is needed for such task. I know that overhead is low, but ideally it should be zero.
- User may want to disconnect recording device between transmissions.
sorry, haven't had a chance to try this myself
So this report is valid and should not be closed?
I was created it not because I can't think of some workaround.
Just because I wanted to help in making this library better.
from naudio.
OK thanks I see. I was just doing a cleanup of old stuff, sounds like this is a genuine bug, but not one I've had time to look at. Very happy to accept PRs for anyone who wants to tackle fixing this. One idea I've had for some time is that the WaveIn
and WaveOut
statuses need to include Starting
and Stopping
states which will make managing edge cases like restarting while we're still stopping much easier.
from naudio.
I just ran into this problem myself. If I record a short clip (say, a second or so) and then call StopRecording()
, then StartRecording()
very shortly thereafter, I get that exception.
from naudio.
thanks for reporting. If I were doing NAudio again from scratch I'd have some additional "starting" and "stopping" states on WaveIn, which I think would make it easier to code around issues where recording (and playback) start and stop very quickly. Remember with recording that you can always capture soundcard data without necessarily "recording" it to a file. This is quite a common approach, so starting recording is just flipping a boolean flag to say we want to keep captured audio. It might help in the short term until we can get this bug fixed.
from naudio.
@markheath Thanks. 👍 Nice little library. Took me no longer than 5 minutes to get it recording to a MemoryStream.
from naudio.
I found a workaround, definely not the best way to handle it but...
You have to create a new WaveIn
and use use the same MemoryStream
each time you want to record.
MemoryStream stream = waveIn.MemoryStream;
waveIn = new WaveIn();
waveIn.MemoryStream = stream;
waveIn.WaveFormat = new WaveFormat(44100, 1);
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += waveIn_RecordingStopped;
// record one time, then stop recording, then create a new WaveIn, and so on...
It's dirty, but it works.
from naudio.
not sure why you need a new instance of WaveIn here? Just start recording again and write to the same memory stream if you want
from naudio.
Do we have a solution for this Exception?
waveIn_RecordingStopped: exception=NAudio.MmException: WaveStillPlaying calling waveUnprepareHeader
в NAudio.MmException.Try(MmResult result, String function)
в NAudio.Wave.WaveInBuffer.Reuse()
from naudio.
// record one time, then stop recording, then create a new WaveIn, and so on...
@anthonyraymond thanks. I tried it and it works, but not for too long.
In my case (I don't use MemoryStream), program leaks handles with every reinitialization.
Which means that after some amount of start-stop cycles, not only your program can't start recording anymore, but any other program in the system.
After I added waveIn?.Dispose();
before waveIn = new WaveIn();
, handle leak stopped.
But who knows what other surprises are still waiting with this solution.
(My comment is vaild for version 1.7.3. What is the behaviour of previous and later versions, I don't know)
from naudio.
Might be worth looking at
WasapiCapture
now that it supports built-in resampling in NAudio 2.1.0
This worked for me! Thanks for the suggestion!
from naudio.
Related Issues (20)
- naudio.core is missing NuGet package README file
- I am trying to make i program to play live microphone audio over the live audio out channel but i am having issues
- Initializing a Wasapi device can tak a long time
- Audio Playback Speed Issue with Multiple Buses in WaveMixerStream32
- why the wavePlayer.PlaybackState was changed to PlaybackState.stopped when I call wavePlayer.Pause()
- Not a standard WAVE PCM soundfile format
- Unable to set SetDuckingPreference HOT 1
- Windows-Independent Mp3FileReader, Load MP3 with NAudio.Core
- Set Licence Expression on package info
- Make Windows.Win32.Registry a conditional package based on TFM
- MediaFoundationReader is not working after I deployed the project to azure HOT 1
- OGG file format support HOT 3
- Bug: possible memory leak
- WasapiLoopbackCapture Http Live Stream HOT 2
- IAudioSessionEventsHandler.OnStateChanged not firing when used inside windows service c#
- .Net Maui IOS crashing HOT 1
- System.MemoryAccessViolation Exception for WaveInEvent
- Read method of Pcm24BitToSampleProvider ignores the offset parameter HOT 3
- waveout ini display error ,can't find a supporte foramt HOT 1
- AutoGain
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from naudio.