【问题标题】:Send audio over skype call通过 Skype 通话发送音频
【发布时间】:2011-11-23 15:15:41
【问题描述】:

当我单击 Windows 窗体上的按钮时,我正在尝试发送音频文件(或直接通过当前输入设备的 Skype 音频)。我找到了一些链接,但所有引用似乎都被破坏了,我对如何使用它感到很生气。

我已经设法连接到Skype api并使用它(我已经将它用于其他项目并且运行良好),但我真的无法通过输入音频流发送任何音频。

任何建议将不胜感激。

当前代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Speech;
using System.Speech.Synthesis;
using SKYPE4COMLib;
using System.Reflection;
using System.IO;

namespace TestSendAudioOnSkype
{
    /// <summary>
    /// Logica di interazione per MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Call CurrentCall = null;
        private Skype SkypeApplet;
        private const int SkypeProtocol = 9;

        private SpeechSynthesizer Speak = new SpeechSynthesizer();

        public MainWindow()
        {
            InitializeComponent();
            try
            {
                SkypeApplet = new Skype();
                SkypeApplet.Attach(SkypeProtocol, true);
                SkypeApplet.CallStatus += SkypeApplet_CallStatus;
                //CurrentCall = SkypeApplet.ActiveCalls[0];
            }
            catch (Exception e)
            {
                MessageBox.Show("errore: " + e.ToString());
                System.Windows.Application.Current.Shutdown();
            }
        }

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

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentCall == null)
            {
                CurrentCall = SkypeApplet.ActiveCalls[1];
            }

            string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string filepath = System.IO.Path.Combine(path,"tmp.wav");
            Speak.SetOutputToWaveFile(filepath);
            Speak.Speak("Hello world");
            Speak.SetOutputToDefaultAudioDevice();
            //Speak.SpeakAsync("Hello world");

            try
            {
                CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, filepath);
                CurrentCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, filepath);
                System.Threading.Thread.Sleep(3000);
                CurrentCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");
                CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");
                MessageBox.Show("invio terminato");
            }
            catch (Exception exc)
            {
                MessageBox.Show("errore: " + exc.ToString());
                //System.Windows.Application.Current.Shutdown();
            }
        }
    }
}

到目前为止我发现了什么:http://community.skype.com/t5/Desktop-API-former-Public-API/Sending-Audio-in-Skype/td-p/422

【问题讨论】:

    标签: c# audio wav skype skype4com


    【解决方案1】:

    看起来问题出在文件格式上,而不是我应该工作的代码。

    这是我在 Skype 论坛上得到的答案:http://devforum.skype.com/t5/Developer-Corner/Skype4COM-and-C-Sending-audio-on-current-call-through-input/td-p/8414?utm_source=Subsciption&utm_medium=Subsciption&utm_campaign=Subsciption

    它有效,我将文件构建为 16 位样本、16khz、单声道 WAV 文件。 下面是使用 System.Speech 库的代码:(Speak 是 SpeechSynthesize 对象)

        Speak.SetOutputToWaveFile(filepath, new System.Speech.AudioFormat.SpeechAudioFormatInfo(
            16000,
            System.Speech.AudioFormat.AudioBitsPerSample.Sixteen,
            System.Speech.AudioFormat.AudioChannel.Mono
        ));
    

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 2013-07-24
      • 2019-09-05
      • 2013-06-07
      • 1970-01-01
      相关资源
      最近更新 更多