skype for business outgoing call and play audio file

牧云@^-^@ 提交于 2019-12-08 04:07:30

问题


Goal is to develop an interface of a systems monitoring solution to a module, which calls an on-call duty person and plays some speech/audio file from file system.

i have an skype for business 2015 (fomerly lync) user with phone options enabled. i am also able to call phone a number. but then the question is, how to wait until the dialed person accepts the phone call and play an audio file (or better is the System.Speech variant instead of playing an audio file) and after that the person has to approve that he/she received the call.

what i currently have:

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);
    }

  }
}

and the other question is, is it possible to change whole module to be a registered endpoint that it can run as a windows service? Currently my sfb has to be opened and logged in..


回答1:


Please note this is NOT UCMA code you posted, it's Lync Client SDK code.

I'm going to assume you want to know how to do what you ask with the Lync Client SDK.

You need to hook the AVModality.ModalityStateChanged event to see know when it changes to the AVModality.State changes to Connected.

Once in the Connected state, you can do what you want.

Adjusting your code I came up with:

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;
        }
    }
}


来源:https://stackoverflow.com/questions/40628236/skype-for-business-outgoing-call-and-play-audio-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!