[英]Capture Audio on PC as a stream in real-time
in NAudio you can capture audio using this code在 NAudio 中,您可以使用此代码捕获音频
capture.Start();
Console.ReadKey();
capture.Stop();
but i don't want to wait for capture.Stop();
但我不想等待
capture.Stop();
i want to access the capture and stream it to another audio device immediately, for example in CsCore you can stream speech synthesis with this code我想立即访问捕获并将其流式传输到另一个音频设备,例如在 CsCore 中,您可以使用此代码流式传输语音合成
using (var stream1 = new MemoryStream())
using (var speechEngine1 = new SpeechSynthesizer())
{
speechEngine1.SetOutputToWaveStream(stream1);
speechEngine1.Speak(text_to_read);
using (var waveOut1 = new CSCore.SoundOut.WaveOut {
Device = new WaveOutDevice(audio_device_id) })
using (var waveSource1 = new MediaFoundationDecoder(stream1))
{
waveOut1.Initialize(waveSource1);
waveOut1.Play();
waveOut1.WaitForStopped();
}
}
can i do something similar like this code but instead of speech synthesis, i want to stream my default audio device to another audio device.我可以做类似这个代码的事情,但不是语音合成,我想将我的默认音频设备流式传输到另一个音频设备。
You can get chunks of bytes by subscribing to an event.您可以通过订阅事件来获取字节块。 https://github.com/naudio/NAudio/blob/master/Docs/WasapiLoopbackCapture.md
https://github.com/naudio/NAudio/blob/master/Docs/WasapiLoopbackCapture.md
capture.DataAvailable += (s, a) =>
{
writer.Write(a.Buffer, 0, a.BytesRecorded);
if (writer.Position > capture.WaveFormat.AverageBytesPerSecond * 20)
{
capture.StopRecording();
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.