I want to capture sound from mic and play it again in speakers in c# but not using Microsoft.DirectX.directsound how?
As an alternative to DirectSound there are the multi-media APIs. I know of no binding that's included with .net, but there are several third party bindings of varying quality.
naudio is a popular .net audio library, but I don't know which API it uses in the background. As long as you avoid the abomination called WaveBuffer you should be fine.
In my project I used Lumisoft.Audio, mainly because it has a simple API. But their code doesn't have a very high quality.
As CodeInChaos mentions NAudio (http://naudio.codeplex.com/) will do the trick. Here is an article from channel 9, which hopefully will help you out:
http://channel9.msdn.com/coding4fun/articles/NET-Voice-Recorder
This is from Mark Heath's NAudio demo (http://voicerecorder.codeplex.com/) as he mentions in this other post: Capture a Microphone Audio Stream Using .NET Framework
Related
I am using in my C# winForms application great audio library - NAudio. I am playing sounds by the use of WAVE cache and PlayEngine and i have a question:
Is it possible (and if YES: how?) to play sound with reverb effect with NAudio?
NAudio does not include a reverb effect. It does provide access to the raw audio samples, so you can implement your own effect algorithms. Another option might be to see if there is a Reverb MFT installed and pass the audio through (in the same way that the NAudio MFResampler works).
So the short answer is, unfortunately it's not easy to do.
My goal is to mix 2 audio files that is one voice and one background music. For mixing I am using NAudio.
The problem is I am getting following exception while reading mp3 file using NAudio's Mp3FileReader.
DllImport cannot be used on user-defined methods
I am using NAudio in Windows Phone 8.1 Silverlight app project. I am not sure if NAudio is useable on WP Silverlight app if its useable then please help by providing a code example or suggest any other library or custom implementation to mix 2 audio files.
No, I'm afraid NAudio is not usable on Silverlight, as it makes lots of calls into Windows APIs which you can't do in Silverlight. You can take a look at the NAudio NLayer project which offers fully managed MP3 decoding. You could use that in conjunction with some of the more generic helper classes in NAudio like the MixingSampleProvider to perform the mixing you require. Of course the next issue would be what you want to do with that mixed audio. Silverlight does have a way of streaming user generated audio using the MediaElement but NAudio does not provide support for this directly.
[DllImport] requires a substantial chunk of code in the CLR, nothing very subtle about the pinvoke marshaller. That's a problem on a phone, it runs a special version of the CLR named .NETCore. Probably better known today as the codebase that spun-off the CoreCLR open source project. Keeping it small required unsubtle choices, pinvoke fell on the floor.
So no, you'll have no use at all for NAudio. You'll have to dip into the built-in support for audio. The relevant oversight MSDN page is this one. This blog post is relevant.
As you can tell, XAudio2 is your ticket with direct support for mixing. There is a learning curve of course, the language is probably the first obstacle given the question tags. Get started with this sample to get the basics.
Maybe you should consider taking the step to upgrade from WP8.1 Silverlight (WPS) project to WP8.1 (WinRT) one so that you have better access to audio APIs...
...or directly to a UWP/Win10 app (if you don't plan to release immediately to phones). If you choose that path, you could try maybe a free preview tool that converts WPS to UWP, just released from Microsoft and Mobilize.NET - https://blogs.windows.com/buildingapps/2015/09/17/initial-preview-of-silverlight-bridge-to-uwp/
Need to record all sounds from sound card. So that mic+output was written to file.
Is it possible to do with NAudio library in Windows 7? Cant find any examples, found just ones that allow to write mic or just sound from speakers, not both.
PS, sorry, if the question looks not ok..Im new to audiorecording.
Added issue ive asked on codeplex: http://naudio.codeplex.com/workitem/16353
To record sounds being played by the soundcard, you would use WASAPI in Loopback Mode.
To record sounds going into the microphone you could use WASAPI capture, or any of the other microphone capture classes in NAudio.
Then you have the slightly tricky job of mixing those two inputs together. This may require sample rate conversion beforehand, and it may require you to timestamp the recorded audio (as the loopback audio can contain gaps when nothing is being played).
With NAudio, you would convert both streams to floating point, before mixing them using one of the "Mixer" wave or sample providers in NAudio, and then writing that back out to a file.
So yes it is possible, and I have done it once before myself, but it does require you to write a fair bit of your own code on top of the core NAudio libraries.
I am building a sip softphone in C#, I am through with the audio aspect, but I want to add video call capability to it, I can successfully get image from the webcamera on the system, but the problem now is I want to compress the image using h.263 codec algorithm before sending it over udp in realtime, all the codes I have been seeing on h.263 is in c++, and I am not a C++ person, please how can I implement this in C#, I mean get the video from the webcamera, encode in h263 and send it over wire in realtime, any suggestion will be highly appreciated
If you want to do real-time streaming over UDP with both audio and video stream you can use the DirectShow API (if you're targeting Windows computers). Official documentation available here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375454(v=vs.85).aspx
You will find a .NET wrapper for DirectShow here: http://directshownet.sourceforge.net/ and also some samples.
You will also find more samples on codeproject.com, most of them use this wrapper: http://www.codeproject.com/kb/audio-video/#DirectShow
Using DirectShow you will be able to capture both the webcam and the microphone in realtime, encode them using the appropriate encoder filter (for instance, a h263 encoder for the video stream) and then send the encoded frames over the network using a RTSP writer filter.
I'm not an expert on DirectShow, but this could be a good starting point. I know this solution works because I've implemented it few months ago.
You need to know that DirectShow is beeing deprecated since Windows Vista, and is beeing replaced by the new API: Windows Media Foundation. If you're targeting Windows Vista or Windows 7 only, it may be a better choice to use the new API. See the MSDN documentation for more details: http://msdn.microsoft.com/en-us/library/windows/desktop/ms694197(v=vs.85).aspx
Hope this will help you.
Is it possible to play a sound on a playback device that is not set as default playback device?
I need to play multiple files simultaniously trough multiple output devices.
Does anyone knows a solution for .net? (C#)
Thanks!
you will have to go to lower level API. You can try find C# wrapper for Wasapi, ASIO, DirectSound or MediaFoundation. Maybe XNA framework could do the job, which is managed framework over directX
well I was playing around with similar issue.
XNA could not do send output to specific device.
I have ended out with http://naudio.codeplex.com/, which is exactly what you need. It's C# wrapper for Wasapi, ASIO, DirectSound libraries. It also includes many very helpful classes for converting, decoding, visualizing etc. For simple player, check out NAudioDemo sample project.
find out CreateWaveOut() method. This is where you should select your playbackdevice.
for example:
MMDevice device = new MMDeviceEnumerator()
.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.All)
.FirstOrDefault(d => d.ID == "yourplaybackdeviceid");
IWavePlayer waveOut = new WasapiOut(device, AudioClientShareMode.Shared, false, latency);
Download the naudio library from sourcecode tab not from Download->Release, it's not very actual and it's little buggy.
another good tool is bass.net
http://www.un4seen.com/