Skype system sound using Naudio

I was there for a while, but made no progress. So this is my last resort! I'm trying to send a system sound (the sound that I hear on my headphones) to Skype (so that people in my conversation hear what I hear mostly). And I thought I would do it using Skype4comlib and naudio.

What I did was create a class that uses WasapiLoopbackCaptureboth WaveFileWriterto write temporary data to a WAV file and redirect audio using the SkypeSystemAudio.set_InputDevice method. But when I talk to someone and I try to start recording, the person can no longer hear me. I'm just completely silent, and no one is playing with a person.

I thought it would be better if I published the whole class, as it was easier to understand everything.

public class SkypeSystemAudio
{
    public NAudio.Wave.WasapiLoopbackCapture capture;
    NAudio.CoreAudioApi.MMDevice device;
    NAudio.Wave.WaveFileWriter writer;
    private Call CurrentCall = null;
    private Skype SkypeApplet;
    private const int SkypeProtocol = 9;
    private bool IsRecording = false;
    public string tempfilepath = System.IO.Directory.GetCurrentDirectory() + @"\temp.wav";
    #region Public
    public void Initialize()
    {
        device = NAudio.Wave.WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice();
        Init();
    }
    public void Initialize(NAudio.CoreAudioApi.MMDevice device)
    {
        this.device = device;
        Init();
    }
    public void StartRecording()
    {
        capture.StartRecording();
        if (CurrentCall != null)
        {

            CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, tempfilepath);
            IsRecording = true;
        }

    }
    public void StopRecording()
    {
        capture.StopRecording();
        if (CurrentCall != null)
        {

            CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");

        }
    }
    #endregion


    private void Init()
    {
        capture = new WasapiLoopbackCapture(device);
        capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
        capture.DataAvailable += capture_DataAvailable;
        capture.RecordingStopped += capture_RecordingStopped;

        WaveFormat format = new WaveFormat(16000, 1); // skype wants 16 Bit samples, 16khz, mono WAV file
        //tried using the standard waveformat in the device object too. Didn't work though.

        writer = new WaveFileWriter(tempfilepath, format );

        SkypeApplet = new Skype();
        SkypeApplet.Attach(SkypeProtocol, true);
        SkypeApplet.CallStatus += SkypeApplet_CallStatus;

    }

    void SkypeApplet_CallStatus(Call pCall, TCallStatus Status)
    {
        if (Status == TCallStatus.clsRinging)
        {
            CurrentCall = pCall;
            pCall.Answer();
        }
    }

    void capture_DataAvailable(object sender, WaveInEventArgs e)
    {
        if (writer != null)
            writer.Write(e.Buffer, 0, e.BytesRecorded);
    }

    void capture_RecordingStopped(object sender, StoppedEventArgs e)
    {
        IsRecording = false;
    }


}

- , ? , .

!

+4
1

- , Skype4COM.

, , " ", , , . , Skype .

enter image description here

enter image description here

/.

enter image description here

VAC VB-

, .

+2

Source: https://habr.com/ru/post/1569121/


All Articles