Getting data from any sound currently playing on an android device? - c#

I am interested to get any sound currently playing on a mobile device, even if it is not playing using the app. Is it possible to monitor the speakers, and get data directly before they play that sound? Like when you plug in the headphones and the speaker stops, but android sends the data to the headset, no matter, where it is playing. If it is, what would be the code?
I did look at this, but this should get only if it is playing or not, and not actuall song data.
Xamarin Android: Detect if audio is currently playing on device

You could try to use the microphone, except when earphones are connected, like Shazam does or the ROG phone to sync the rgb with the audio.

Related

How can I determine the process that playing sound via C#?

I use one music player and I'd like to develop a plugin for it in C#.
The plugin should stop playing, when others programs start playing, for example youtube in Chrome or Skype.
Is it possible to monitor all sound sources in Windows via C# or any other language?

How to tell if webcam can capture audio as well?

I have little desktop app which uses UWP API to capture data from webcam (MediaCapture). On my computer it works fine -- I can capture video and audio. When I run the same program on the other computer it crashes -- as I found out I had to disable audio recording:
var media_settings = new MediaCaptureInitializationSettings();
// audio+video by default
media_settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
await mediaCapture.InitializeAsync(media_settings);
Is there a way to find out in advance if given webcam supports audio recording? By "in advance" I mean the other way than trying, catching exception and in second take disabling audio :-).
You can find out if the given webcam supports audio recording by enumerating the audio devices before you initialize the MediaCaptureInitializationSettings object. After finishing enumerating the audio device, you can find whether there is a audio device from the webcam or not.
You can follow the Enumerate devices topic or see the DeviceEnumerationAndPairing sample directly to find the AudioCapture device, then you should be able to judge if there is a audio device from the webcam.

c#/.NET - Recording the current audio being played

Is there any way in c#/.net of recording the current audio being played? I've searched a lot on the internet but the only result I could find is recording using a microphone.
I dont want to record using microphone input, I want to record what is being played on the computer when I click a record button.
Thanks
You have two options here:
Hardware loopback device - virtual "Stereo Mix" audio device, which acts as a regular audio capture device and in the same time produces a copy of mixed audio feed played through default audio output device of the system. Since such device shows up as real audio input device, you can use standard APIs, libraries and even exitsing applications to record from such device.
Programmatic access to a virtual loopback device as if it was microphone-like device. API on the background will duplicate played audio content and make it available for reading back as it plays. The good news is that you can access the mixed audio feed for device of your interest.
Both options are described in detail in Loopback Recording article on MSDN and available via standard audio APIs, specifically WASAPI.
For C# development you are likely to use a wrapper like NAudio.
For option 1 you will find quite a few questions on StackOverflow, and for the other option the keyword is AUDCLNT_STREAMFLAGS_LOOPBACK.
The only way to be able to receive data from another application is if the developer provides an access point, normally through some SDK, API, or other means. Without this, there is no way for your application code to receive the bytes from the other application.
The reason a microphone works is because it is receiving the sound output bytes from the application and sending those soundwave bytes back into your PC to render and output the sound. Since you have access to these bytes from the microphone you are able to capture the sound.
See if there is an API or an SDK from the developer of the application you are trying to get sound from.

C# Play generated sound (present in array) on default speaker & receive using default microphone

I am developing universal windows app (C#/Xaml) I am able to play a sound from .wav file but now I want to play sound which I am generating on runtime. It will be generated well before playing. How Can I play generated sound (present in array) on default speakers. And I also want to receive the played sound (i know there will be noise NO ISSUES) using default microphone and put the recorded data in array. Any help would be appreciable.
Regards

How can I send an audio stream from the output device to an input device?

I am working on a project where I am playing a wave file using naudio to someone over the phone through a softphone. The person making the call, wearing a usb headset (which is an external soundcard) would need to be able to speak along with the wave files. Right now I'm running a dual 3.5mm audio cable from the output into the input on the back of the computer to make this happen. This is making me have to use the onboard sound card for the wave and the head set for the person to speak which means I have to switch the default input audio device on-demand to allow the person to be heard or the wave to be heard. This causes issue with the softphone app depending on how its devices are set. I want to cut out the onboard soundcard altogether. I want to send both my wave audio and the person speaking, into the same input device.
When I play the audio this is the code I call:
WaveStream waveStream = new WaveFileReader(#"C:\Users\Public\Music\tester.wav");
WaveOut waveOut = new WaveOut();
waveOut.DeviceNumber = int.Parse(device1);
WaveOut.Init(waveStream);
WaveOut.Play();
At this point I would love to not only send to the selected output device but also to an input device as well. Is there any simple ways I can do this? Thanks for your help in advance.
Unfortunately, the various Windows audio APIs provide no way for you to replace the audio received by an actual input device with your own audio, so this isn't something you can achieve out of the box with NAudio. What you need is to create a virtual audio input device. This is quite a lot of work, so the simplest solution is to purchase something like Virtual Audio Cable, which will allow you to create virtual sound devices and patch them together.

Categories

Resources