当我点击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
答案 0 :(得分:4)
看起来问题与文件格式有关,而不是我的代码应该有效。
它有效,我将文件构建为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
));
希望这个帮助