I have been using the code in http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html to record audio. Basically this code:
WaveIn waveInStream;
WaveFileWriter writer;
waveInStream = new WaveIn(44100,2);
writer = new WaveFileWriter(outputFilename, waveInStream.WaveFormat);
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
It works perfectly and record every sound on the system. The problem arises when I pluck in a headset (not usb, just directly into the headset jack on the built in soundcard on my laptop). This has the effect that any sound I can hear in the headset is not recorded.
I think it has something to do with which device i am recording from, but I can't quite figure it out.
I am trying to record a conversation, which means I would like to record the sound that comes from the mic and the sound I can hear in the headset at the same time.
Can someone point me in the right direction for this? Thanks.
// Get default capturer
waveInStream = new WaveIn(44100,2);
Now if you plug in your headset microphone/speaker then Windows will detect it but your program is still using the old 'default' endpoint. Not the lastly added device. This needs to be updated.
One of the solution would be to poll the endpoints and see if any new (default) device has been added to the system and then stop-start the recording with the new device.
waveInStream.StopRecording();
// assign the default recording device if not already done
//waveInStream.DeviceNumber = 0;
waveInStream.StartRecording();
Let me know if I was not very clear in the explanation.
Related
I've installed the Microsoft Teams(work or school / version 1.6.00.1381 ) app on Win 11.
I'd like to detect whether microphone within a call is muted or not.
I found this https://stackoverflow.com/questions/67569705/get-current-call-status-of-microsoft-teams ,
someone said : Currently there is no api to get the current microphone state within a call.
Now I have a workaround to know the microphone status on Teams by NAudio
step1: set mute/unmute
using var deviceEnumerator = new MMDeviceEnumerator();
var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
_isMicMuted = !_isMicMuted;
foreach (var device in devices)
{
device.AudioEndpointVolume.Mute = _isMicMuted;
}
step2: get microphone status
devices.Any(x => x.AudioEndpointVolume.Mute);
This way will fail because when user manually press unmute/mute mic button,
it didn't change device.AudioEndpointVolume.Mute value.
enter image description here
is there any other way do this?
I am using Lecia Disto e7100i which basically measures distance and area using laser. This device has bluetooth and can be paired with windows.
I am trying to develop an wpf app that reads the mesaured data using c#
There is no sdk that comes along with the device.
I have tried to use 32feet.Net but since there is no proper documentation I don't know where to start.
Is there any way that I can do to solve my problem?
This is not a full response, instead its more of a guideline on how to resolve your issue:
Pair the device with your Computer
Run the included software that displays the data somehow
Use WireShark to analyze the traffic
see if it is a standard protocol type or something custom
understand the protocol and reimplement it using c# and BluetoothSockets
To get started, you can try:
var client = new BluetoothClient();
// Select the bluetooth device
var dlg = new SelectBluetoothDeviceDialog();
DialogResult result = dlg.ShowDialog(this);
if (result != DialogResult.OK)
{
return;
}
BluetoothDeviceInfo device = dlg.SelectedDevice;
BluetoothAddress addr = device.DeviceAddress;
Console.WriteLine(device.DeviceName);
BluetoothSecurity.PairRequest(addr, "PIN"); // set the pin here or take user input
device.SetServiceState(BluetoothService.HumanInterfaceDevice, true);
Thread.Sleep(100); // Precautionary
if (device.InstalledServices.Length == 0)
{
// handle appropriately
}
client.Connect(addr, BluetoothService.HumanInterfaceDevice);
Also make sure that
Device appears in "Bluetooth devices" in the "Control panel".
Device is HID or change code accordingly.
Hope it helps. Cheers!
Try this demo project, and the following articles after that one.
Try to follow this tutorial
Here you can see a direct answer by the mantainer of 32feet, with which you can get in touch
Check also this answer
I'd like to play a soundfile from the speakers integrated in the laptop, even if an additional speaker is connected via the headphone jack (but it's not listed in the sound device list).
I've had a look at How can I make the computer beep in C#? and How to beep using PC speaker? and have understood that the beep driver was removed in windows 7.
However, I do not want to use this extremely simple integrated speaker controlled by the removed driver, but the normal one present in most modern laptops.
Unfortunately, when I connect my external speakers, they do not show up as an additional device. When I run this code (using NAudio), I always get just one result, and it's the same whether the external speakers are connected or not:
var enumerator = new MMDeviceEnumerator();
foreach (var endpoint in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active))
{
Console.WriteLine(endpoint.FriendlyName);
}
Is it possible to play a sound on the normal laptop speaker, while an external speaker is connected?
Edit:
I don't think my question is a duplicate of Play a sound in a specific device with C#
I don't see an additional device when I connect my external speakers, so I guess my laptop doesn't have multiple sound cards (how can I verify?).
The solution from the other question (waveOut.DeviceNumber = deviceNumber;) doesn't work for me neither. When I choose deviceNumber = 0;, the sound comes from my external speaker if it's connected. If I set deviceNumber = 1; (while it's connected) I get a MmException
I see I'm a bit late for the party but i was working on something similar and got to this solution.
Hope it helps someone in the future :)
var enumerator = new MMDeviceEnumerator();
IWavePlayer waveOut = new WasapiOut();
foreach (var endpoint in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active))
{
if (endpoint.FriendlyName == "Name of the device you want")
{
waveOut = new WasapiOut(
endpoint, AudioClientShareMode.Exclusive, false, 0);
AudioFileReader wave = new AudioFileReader("Audio Name");
waveOut.Init(wave);
waveOut.Play();
break;
}
}
Am recording the video by intel real sense camera. The video recording is done and working successfully. But audio is not coming in that video.
For that my question is...
My configuration is Lenovo Yoga 15 with internal real sense camera
I want to install audio driver for sound ? Is that are required ?
please give me some suggestion.
session = PXCMSession.CreateInstance();
senseManager = session.CreateSenseManager();
senseManager.captureManager.SetFileName("new4.rssdk", true);
senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, WIDTH, HEIGHT, 30);
senseManager.Init();
for (int i = 0; i < 200; i++)
{
if (senseManager.AcquireFrame(true).IsError()) break;
PXCMCapture.Sample sample = senseManager.QuerySample();
senseManager.ReleaseFrame();
colorBitmap.Dispose();
}
I didn't understand the question well, so do you want to run audio and record the video together?
If yes, you have to create an instance of the class responsible for doing that.
take a look here Speech Recognition
I used two threads in order to do that. I have an application where I use facial recognition and audio recognition. I decided to split them and it worked very well.
I'm using a MediaPlayerLauncher to show movietrailers in my WP7 application, like this:
MediaPlayerLauncher mpl = new MediaPlayerLauncher();
mpl.Media = new Uri(trailerUrl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
This works just fine, except one thing: if the user is already listening to music in the background, and launch a trailer, the music is not resumed after the trailer is done playing (or if the user closes the video).
Does anyone know how i can resume the previously playing music/media, if even possible?
Local media playing through XNA or a 'background audio agent'?
When you play media in WP7 / WP8, the OS audio context is taken, and the original context is lost. If the audio was launched from an external application, then you cannot resume at all. If the previous media was launched from within your application, then you could store the meta-data and re-play once your trailer is finished. The media would, of course, then begin playing from the start, rather than where the user left off. Unfortunately XNA does not allow you to seek within a given piece of media; however you can seek within an 'audio agent' instance of 'BackgroundAudioPlayer' by setting player.Position. It's also worth looking at the MediaHistory API:
var nowPlaying = Microsoft.Devices.MediaHistory.Instance.NowPlaying;
Figured it out. Calling MediaPlayer.Resume() right after show() solves the issue:
mpl.Media = new Uri(trailerurl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
MediaPlayer.Resume();
However, i would still like to know how to resume radio and spotify!