2011-11-23 154 views
3

當我單擊Windows窗體上的按鈕時,我試圖發送音頻文件(或直接通過當前的Skype輸入設備進行音頻)。我發現了一些鏈接,但所有引用似乎都被破壞了,我正在爲如何使用它而生氣。通過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

貌似問題是關於文件格式,而不是直接我的代碼應該工作。

這是我作爲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庫中的代碼:(說是SpeechSynthesize對象)

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

希望這有助於