I am working on integrating NAudio to a MAUI based application. I have successfully written the code to merge the audio from Mic and Speakers and it is streaming to the server via Web Socket Protocol. The file generated through the stream on the server shows its size when checked from the properties whereas the length is zero
I am not sure what went wrong. Any suggestions are highly appreciated.
BTW, here is my code to read audio from Mic and Speakers and generating an output File by mixing both the audios
string serverUrl = "wss://localhost:7193/audio";
// Initialize WebSocket
webSocket = new ClientWebSocket();
await webSocket.ConnectAsync(new Uri(serverUrl), CancellationToken.None);
cts = new CancellationTokenSource();
// Initialize audio capture devices
micCapture = new WasapiCapture();
speakerCapture = new WasapiLoopbackCapture();
waveFormat = micCapture.WaveFormat; // Use the mic's format for consistency
micBuffer = new BufferedWaveProvider(waveFormat);
speakerBuffer = new BufferedWaveProvider(waveFormat);
// Mix the audio streams
mixer = new MixingSampleProvider(new ISampleProvider[]
{
micBuffer.ToSampleProvider(),
speakerBuffer.ToSampleProvider()
});
// Start capturing
micCapture.DataAvailable += (s, e) => micBuffer.AddSamples(e.Buffer, 0, e.BytesRecorded);
speakerCapture.DataAvailable += (s, e) => speakerBuffer.AddSamples(e.Buffer, 0, e.BytesRecorded);
micCapture.StartRecording();
speakerCapture.StartRecording();
// Stream audio data to the server
await Task.Run(() => StreamAudio(cts.Token));