3

当我单击 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

4

1 回答 1

4

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

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

它可以工作,我将文件构建为 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
    ));

希望这有帮助

于 2011-11-24T02:01:51.790 回答