filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.2k stars 454 forks source link

pipe audio to standard pipe #339

Open veso266 opened 6 years ago

veso266 commented 6 years ago

Hi I was wondering how can I pipe audio stream to a standard pipe instead to an audio device

Thanks for Anwsering and Best Regards

filoe commented 6 years ago

What do you mean with a "standard pipe"?

veso266 commented 6 years ago

Hi I mean | pipe: https://en.wikipedia.org/wiki/Pipeline_(Unix)

like sox or ffmpeg has that you are able to transfer audio between more commandLine applications

filoe commented 6 years ago

So, you would like to write it to stdout?

veso266 commented 6 years ago

yes not sure how other programs manage to write audio to there

filoe commented 6 years ago

So you just want to decode an input and write the raw data to stdout? You can write it to any stream:

using(var stream = Console.OpenStandardOutput())
{
    IWaveSource source = ...
    source.WriteToStream(stream);
}
veso266 commented 6 years ago

Hi Thanks for helpinh I tried to play with it today like this

            using (var soundIn = new WasapiCapture(true, AudioClientShareMode.Shared, 30))
            {
                //important: always initialize the soundIn instance before creating the
                //SoundInSource. The SoundInSource needs the WaveFormat of the soundIn,
                //which gets determined by the soundIn.Initialize method.
                soundIn.Initialize();
                using (var stream = Console.OpenStandardOutput())
                {
                    IWaveSource source = new SoundInSource(soundIn) { FillWithZeros = true };
                    source.WriteToStream(stream);
                }
            }

but get a weird exeption: System.IO.IOException: There is not enough space on the disk there is 3GB space on the disk and this should write to stdout not disk right?

Thanks for Anwsering and Best Regards

filoe commented 6 years ago

Where does the exception occur? CSCore won't use any storage on the disk. I would guess it is caused somewhere within the StandardOutput stream. Can help you on that.