简体   繁体   English

使用Naudio将系统音频发送到Skype

[英]System audio to Skype using Naudio

I've been at this for a while, but made no progress. 我已经有一段时间了,但没有取得任何进展。 So this is my last resort! 所以这是我最后的手段! I am trying to send the system-audio (the audio I hear in my headphones) to Skype (making the persons in my call hear what I hear basically). 我正在尝试将系统音频(我在耳机中听到的音频)发送到Skype(让我的通话中的人听到我基本听到的内容)。 And I thought I would do this using the Skype4comlib and naudio. 而且我想我会使用Skype4comlib和naudio来做这件事。

What I've done is to create a class which uses the WasapiLoopbackCapture and WaveFileWriter to write temporary data to a .wav file, and redirect audio using the SkypeSystemAudio.set_InputDevice method. 我所做的是创建一个类,它使用WasapiLoopbackCaptureWaveFileWriter将临时数据写入.wav文件,并使用SkypeSystemAudio.set_InputDevice方法重定向音频。 But when I'm talking to somebody and I try to start recording, the person doesn't hear me anymore. 但当我与某人交谈并尝试开始录音时,该人不再听到我了。 I just go completely quiet and no sound is being played to the person. 我只是完全安静,没有声音播放给这个人。

I thought it would be best if I posted the whole class since it's 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;
    }


}

Does anyone know why this isn't working? 有谁知道为什么这不起作用? I have no clues anymore what to do next. 我没有线索了下一步该做什么。

Any help will greatly appreciated! 任何帮助将不胜感激!

I have actually done some something similar, but not using Skype4COM. 我实际上做了类似的事情,但没有使用Skype4COM。

What I did was using "Virtual Cables" just like Sebastian L suggested, this way you can control whats going in and out off skype, the downside is that you need to install the virtual cables and configure Skype to use them. 我所做的就是像Sebastian L建议的那样使用“虚拟电缆”,这样你可以控制进出skype的内容,缺点是你需要安装虚拟电缆并配置Skype才能使用它们。

在此输入图像描述

在此输入图像描述

The cables will appear in audio devices as standard input/output. 电缆将作为标准输入/输出出现在音频设备中。

在此输入图像描述

I have used these cables VAC and VB cable 我用过这些电缆的VACVB电缆

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM