Capturing microphone audio using Naudio + WASAPI? - capture

I am looking for an example code on how to capture microphone audio using Naudio + WASAPI.
(I am not interested in direct to disk recording, what i need is to process the input buffer in realtime in order to do some audio effects.)
I've searched a lot, but could not find any decent sample online.
Can you please help?
P.S. BASS library and C# examples are welcome as well!

The NAudio source code comes with a demo app that shows how to capture audio using WASAPI. Look in NAudioDemo\RecordingDemo\RecordingPanel.cs.

MSDN has a lot of code samples, though not covering NAudio they do have a few samples that show in detail how to use the Windows Audio Session API.
Since WASAPI is a native-only API there are both sample projects that show you how to use that API from a native-only app Here as well as samples that show you how to build a native component that wraps the API for consumption from a CSharp application. I couldn't find the direct link to the C#/C++-sample but it's included in the Windows 8 App Samples package. Then there's the option of writing a managed wrapper for the API altogether but unless you enjoy pain and are looking for an adventure in marshaling I wouldn't recommend it...
If you're developing for Windows Phone then there's a VOIP-sample in the WP8 SDK that covers how to capture and render PCM audio data using WASAPI.
As Mark pointed out, the size of the pcm data buffer might differ over time and this is in part due to the fact that WASAPI is a low-latency Audio API and therefore has as little abstraction between the consumer (your app) and the producer (the driver) as possible. Though there's nothing that stops you from doing some fixes size buffering of your own and only pass on the data to your app when your own buffer is full.

Related

How to play live audio stream using Google Actions Dialogflow

I have been trying to find a way to play live stream of audio (mp3) using Google Actions but haven't found a way to do so.
I tried Media Response as well but as mentioned in the documentation it doesn't support live stream.
I followed this thread but it doesn't have any examples to help me with.
Is it possible to play live mp3 stream using Google Actions?
I've had relatively good results with the Media Player being able to handle mp3 "streams". There are a couple of problems doing this, however:
There is a time limit on the audio playback (4 hours last time I checked, but it may have changed).
There isn't any such thing as an mp3 "stream". The player treats it as a single mp3 file that it downloads in chunks using HTTP headers, unlike some of the streaming protocols that allow for varying bitrate based on network and other conditions.
If this is an issue, one alternative might be to use the Interactive Canvas (which uses Chrome on the device) to present an HTML page that has an <audio> tag in it that you control. This gives you a little more control (most streaming protocols are either supported or have JavaScript libraries that can do the work), but there are some downsides:
This will only work on Smart Displays and Android. Smart Speakers aren't supported.
Interactive Canvas is only allowed for certain types of Actions. Currently it must be a game, a story, or an educational Action.

4K MJPEG Camera Video Preview with delay (on Windows 10)

I'm trying to preview video stream from 4K Camera (Brio) in my application. The application uses DirectShow to open camera and receive frames. Filter configuration is shown in image below.
The problem are high resolutions (ie. 4096x2160). With 4096x2160 resolution both GraphEdit and my application have delay when I preview video stream.
I'm testing this on Windows 10. Note that Windows 10 preinstalled Camera application works perfect with this resolution. I've also tried the same with UWP sample using MediaCapture Api, but the problem is the same.
What am I missing?
Windows 10 preinstalled Camera application does not use DirectShow, uses completely different code path based on Media Foundation API and is overall more efficient in JPEG decompression in particular. That is, you cannot compare directly your DirectShow based graph to what Windows Store Camera app is doing.
In your situation MJPEG Decompressor Filter is an outdated piece of software incompatible with this resolution and is a bottleneck. Also for live video DirectShow graph needs to have Smart Tee Filter.
Performance wise I would recommend to build media pipeline on Media Foundation, even though it is more difficult and comes with less documentation and samples.

How implement real time video encoding using Libde265 and Linux

I been reading a lot about H265 encoder but I'm no really sure how to start a C or Python application to encode a video stream in real time using H.265 encoder from libde265, I all ready install the library and I guess I could use opencv to get the input video stream from a usb camera, do anyone has worked in this type of application ?
If you are not particular about using libde265, which I am not aware of, please give a shot with gstreamer. gstreamer has lots of plugins and examples if you are doing some standard tasks like encoding on your stream. It also integrates well with native development.
I have worked on a project similar to yours, where we did H264 encoding and decoding along with few other things on a live camera feed.
Please find the video of a similar application here: https://www.youtube.com/watch?v=JcpkGDpfVU0
Just my two cents!!

How to redirect audio stream from microphone to headphone instantly

I need to open the incoming audio stream from the microphone and address it instantly to the headphones so you hear what is being acquired by the microphone.
it is not possible to do this using xna microphone, because it is necessary to pass through a buffer that slows down the headphone listening. I think needs to use Windows.Phone.Media.Capture as AudioDevice and perhaps AudioSink but do not understand how. Do you have any suggestions?
thanks
It looks you've got tighter latency requirements than the a previous question in this area. For phone 8 the best latency result is probably going to be to use the DirectX audio APIs from C++.
The documentation on MSDN will tell you which APIs you can use from the phone, but if I know MSDN I expect you will need to go digging to find examples of how to use them - and when you find them you'll need to be familiar with C/C++, and how to set up a "hybrid" C#/C++ project in Visual Studio.
Even then you'll have to try and it out on a real phone to see if the latency performance is good enough for your purposes.

Streaming audio to a browser

I have a large amount of audio stored on my web server in a very custom format that can't be replayed by anything other than my own application. That application is a Win32 app that can connect to my web server and stream and replay that audio.
I'd really like to be able to do the streaming and replaying from within a browser, but don't know where to start. Ideally I'd like the technology to be cross-platform (unlike my current Win32 app) and cross-browser (IE 6 and above and Firefox).
My current thoughts are to look at things like:
Flash, but doesn't that only replay mp3 audio?
Java, are VMs freely available still?
Converting the audio to a WAV file on the web server and then using someone else's plugin to replay that file. I'd rather keep the conversion off the web server for performance reasons, but is still an option.
Writing my own custom plugin to do the complete stream and replay operation.
Any guidance would be most useful.
Please note that the audio is not music and that simply converting to another audio format is not trivial. The audio that is stored also changes frequently (every minute) would need constant conversion.
Why are you using a proprietary music format? I'd probably not even bother downloading a program to listen to it.
I would suggest you convert it to mp3 and then use flash.
Building your own plugin would probably be hard, there are so many different platforms you'd have to cater for, something like flash is written for them already.
Apart from converting server-side: Implement a decoder for your format in ActionScript or Java. Then you can write a Flash movie or Java applet that plays it. Both languages/runtimes should be fast enough to decode in realtime unless your format is very complex. Flash would be the more accessible of the two, since nearly everyone has the plugin installed. (It's possible that playing a raw sound buffer isn't supported by older Flash versions than 10, I'm no expert on that.) The Java plugin is definitely free, but you'd require the users to install it.
I'd go with converting the audio to WAV (or MP3) on the server. Writing your own cross-platform browser component would be a lot of work, thanks to the different ways the major OSes handle their audio APIs.
Try taking a look at shoutcast.
Basically its a server app that will stream music to any client that connects to it through a browser (effectively your own radio station). I've never used it myself but should be straight forward.
Another idea is winamp remote. Again you install the app on the server but this time you can browse your music collection on their website and play individual songs.

Resources