当我点击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
看起来问题是关于文件格式,而不是直接我的代码应该工作。
这是我在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的代码。语音库:(Speak是一个语音合成对象)
Speak.SetOutputToWaveFile(filepath, new System.Speech.AudioFormat.SpeechAudioFormatInfo(
16000,
System.Speech.AudioFormat.AudioBitsPerSample.Sixteen,
System.Speech.AudioFormat.AudioChannel.Mono
));
希望对您有所帮助