Skype for Business 拨出电话和播放音频文件

skype for business outgoing call and play audio file

目标是为一个模块开发一个系统监控解决方案的接口,它调用一个值班人员并从文件系统播放一些speech/audio文件。

我有一个启用了 phone 选项的 Skype for business 2015(以前称为 lync)用户。我还可以拨打 phone 号码。但接下来的问题是,如何等到被拨叫的人接受 phone 呼叫并播放音频文件(或者更好的是 System.Speech 变体而不是播放音频文件),然后这个人有批准 he/she 接到电话。

我目前拥有的:

public void SendLyncCall(string numberToCall, string textToSpeech)
{
  var targetContactUris = new List<string> {numberToCall}; //"tel:+4900000000" }; //removed here

  _automation.BeginStartConversation(AutomationModalities.Audio, targetContactUris, null, StartConversationCallback, null);

    while (this.globalConv == null)
    {
      Thread.Sleep(1);
    }
  if (globalConv != null)
  {
    LyncClient client = LyncClient.GetClient();

    client.DeviceManager.EndPlayAudioFile(
      client.DeviceManager.BeginPlayAudioFile(@"d:\tmp\test1.wav",
        AudioPlayBackModes.Communication,
        false,
        null,
        null));
  }
}

private void StartConversationCallback(IAsyncResult asyncop)
{
 // this is called once the dialing completes..
if (asyncop.IsCompleted == true)
{

    ConversationWindow newConversationWindow = _automation.EndStartConversation(asyncop);
  globalConv = newConversationWindow;
    AVModality avModality = globalConv.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;


    foreach (char c in "SOS")
    {
      avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
      System.Threading.Thread.Sleep(300);
    }

  }
}

另一个问题是,是否可以将整个模块更改为注册端点,以便它可以 运行 作为 windows 服务?目前我的sfb必须打开并登录..

请注意这不是 UCMA code you posted, it's Lync Client SDK 代码。

我假设您想知道如何使用 Lync Client SDK 完成您的要求。

您需要挂钩 AVModality.ModalityStateChanged event to see know when it changes to the AVModality.State changes to Connected

一旦进入连接状态,您就可以为所欲为了。

正在调整我想出的代码:

private void StartConversationCallback(IAsyncResult asyncop)
{
    // this is called once the dialing completes..
    if (asyncop.IsCompleted == true)
    {
        ConversationWindow newConversationWindow = _automation.EndStartConversation(asyncop);
        AVModality avModality = newConversationWindow.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;
        avModality.ModalityStateChanged += ConversationModalityStateChangedCallback;
    }
}

private void ConversationModalityStateChangedCallback(object sender, ModalityStateChangedEventArgs e)
{
    AVModality avModality = sender as AVModality;
    if (avModality != null)
    {
        switch (e.NewState)
        {
            case ModalityState.Disconnected:
                avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
                break;

            case ModalityState.Connected:
                avModality.ModalityStateChanged -= ConversationModalityStateChangedCallback;
                foreach (char c in "SOS")
                {
                    avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
                    System.Threading.Thread.Sleep(300);
                }
                break;
        }
    }
}