How to make a call to external phone and play a media file

Version 1
    This document was generated from CDN thread

    Created by: Marat Rabidinov on 26-05-2011 01:04:17 AM
    Hi.
    I wonder how to make a call to external phone and play a media file to it?
    Can anybody give me an example?

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Raghavendra Gutty Veeranagappa on 26-05-2011 01:30:59 AM
    Hi Marat,

    please find samples and documents in below link,are you trying to play media to the ougoing leg if so you can use following command.

    media play leg_outgoing flash:en_enter_dest.au.

    http://developer.cisco.com/web/vgapi/docs

    Thanks,
    Raghavendra

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Raghavendra Gutty Veeranagappa on 31-05-2011 07:28:06 AM
    Hi Marat,

    ok, what do you mean by Cisco ?  is it some extension, is speech take place between Cisco and 05550052xx after script make call to external phone.

    Thanks,
    Raghavendra

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Marat Rabidinov on 31-05-2011 01:23:03 AM
    Ok.
    I have writed a script which call to external phone and must play a media file to leg_outgoing.
    But I have a silence on external phone.

    Dial-peer:
    1dial-peer voice 10 voip
    2  destination-pattern 05550052¿¿
    3  session target ipv4:192.168.201.2
    4  codec g711ulaw


    TCL script - balance:
     1proc init { } {
     2                global param callinfo numExt1
     3
     4                infotag set med_language_map 0 ru
     5                infotag set med_location ru 0 tftp://¿¿.¿¿.21.173/path/media/
     6                infotag set med_language 0
     7
     8                set id "1"
     9                set callinfo(alertTime) 10
    10                set callinfo(originationNum) "¿¿6979"
    11
    12                set numExt1 "05550052¿¿"
    13}
    14
    15proc act_MakeCall { } {
    16                puts "DEBUG: act_MakeCall start"
    17                global param callinfo numExt1
    18
    19                leg setup $numExt1 callinfo leg_outgoing
    20
    21                puts "DEBUG: act_MakeCall stop"
    22                fsm setstate CHECKCALLSETUP
    23}
    24
    25proc act_CheckCallSetup { } {
    26                puts "DEBUG: act_CheckCallSetup start"
    27
    28                global param Status
    29
    30                set Status [infotag get evt_status]
    31                switch $Status {
    32                                "ls_000" {
    33                                                media play leg_outgoing _welcome.au
    34                                                puts "DEBUG: CALL ACTIVE true"
    35                                }
    36                                default {
    37                                                puts "DEBUG: CALL FAILED, STATUS - $Status"
    38                                }
    39                }
    40
    41                puts "DEBUG: act_CheckCallSetup stop"
    42}
    43
    44proc act_AfterMedia { } {
    45                puts "DEBUG: Media Finished"
    46                act_Cleanup
    47}
    48
    49proc act_Cleanup { } {
    50                puts "DEBUG: act_Cleanup start"
    51                set status [infotag get evt_status]
    52                puts "DEBUG: STATUS is $status"
    53                call close
    54                puts "DEBUG: act_Cleanup stop"
    55}
    56
    57requiredversion 2.0
    58init
    59
    60# State Machine
    61set fsm(any_state,ev_disconnected) "act_Cleanup same_state"
    62set fsm(CALL_INIT,ev_session_indication) "act_MakeCall CHECKCALLSETUP"
    63set fsm(CHECKCALLSETUP,ev_setup_done) "act_CheckCallSetup MEDIAPLAY"
    64set fsm(MEDIAPLAY,ev_media_done) "act_AfterMedia CALLDISCONNECT"
    65set fsm(CALLDISCONNECT,ev_media_done) "act_Cleanup same_state"
    66set fsm(CALLDISCONNECT,ev_disconnect_done) "act_Cleanup same_state"
    67set fsm(CALLDISCONNECT,ev_leg_timer) "act_Cleanup same_state"
    68
    69fsm define fsm CALL_INIT


    Execution:
     1Router#call application session start my_balance balance
     2Router#
     3May 31 11:07:41.733: //-1//TCL :EEC0EC34BC000:/tcl_PutsObjCmd: DEBUG: act_MakeCall start
     4May 31 11:07:41.733:
     5May 31 11:07:41.733: //-1//TCL :EEC0EC34BC000:/tcl_PutsObjCmd: DEBUG: act_MakeCall stop
     6May 31 11:07:41.733:
     7May 31 11:07:47.877: //-1//TCL :EEC0EC34BC000:/tcl_PutsObjCmd: DEBUG: act_CheckCallSetup start
     8May 31 11:07:47.877:
     9May 31 11:07:47.877: //-1//DPM :DP1295:/pc_mc_createDynamicS: calloc mcDynamicS_t
    10May 31 11:07:47.877: //-1//DPM :DP1295:/pc_mc_addToDynamicS: (1) _welcome.au
    11May 31 11:07:47.877: //-1//DPM :DP1295:/pc_mc_addToDynamicS: Doing : _welcome.au
    12May 31 11:07:47.877: //-1//DPM :/mcTokenizerGetNext: savedcharptr=_ endptrptr=_welcome.au
    13May 31 11:07:47.877: //-1//DPM :DP1295:/pc_mc_addToDynamicS: Token : _welcome.au status 1
    14May 31 11:07:47.877: //-1//DPM :DP1295:/pc_mc_addToDynamicS: call dp_mcDQfromFileDynamic() to Handle relative file name
    15
    16May 31 11:07:47.877: //-1//DPM :DP1295:/dp_mcDQfromFileDynamic: pLanguage=ru FileName=_welcome.au
    17May 31 11:07:47.877: //-1//DPM :DP1295:/dp_mcDQfromURL: file=tftp://¿¿.¿¿.21.173/path/media/ru_welcome.au
    18May 31 11:07:47.877: //-1//MCM :/mc_createFromFileUrl: Getting a media content: name=ru_welcome.au
    19        url=tftp://xx.xx.21.173/path/media/ru_welcome.au
    20        load fast, fetchtimeout=-1
    21May 31 11:07:47.877: //-1//MCM :MC8:/mc_getFromUrlName: ru_welcome.au on ram
    22May 31 11:07:47.877: //-1//MCM :MC8:/mc_waitq_unlink: elm=73DA58C4
    23May 31 11:07:47.877: //-1//MCM :MC8:/mc_waitq_unlink: prompt_wait=C0F88 prompt_active=0
    24
    25May 31 11:07:47.877: //-1//MCM :MC8:/mc_waitq_delete: prompt_wait=C0F88 prompt_active=22D12
    26May 31 11:07:47.877: //-1//MCM :/mc_createFromFileUrl: Found a good mc (0x64E0C834), RefCount(1)
    27May 31 11:07:47.877: //-1//DPM :DP1295:/dp_mcDQfromURL: mc_createFromFileUrl OK
    28May 31 11:07:47.877: //-1//DPM :LP:DP1295:MC8:/dp_mcDQfromURL:
    29May 31 11:07:47.877: dp_mcDQfromURL enqueuing ru_welcome.au OK###
    30May 31 11:07:47.877: //-1//DPM :/mcTokenizerGetNext: savedcharptr= endptrptr=
    31May 31 11:07:47.877: //3303//MSW :/msw_create: cbf=0x6213F128
    32May 31 11:07:47.877: //-1//MSM :MS1313:/ms_create: Iniz ply_timer
    33May 31 11:07:47.877: //3303//MSW :/msw_synth_open: mediaStream 0x73697E30 created
    34May 31 11:07:47.877: //3303//MSW :/msw_synth_open: rtspStream 0x6734BE3C created,
    35                        status=RTSP_STATUS_SUCCESS, session_id=0x521 (1313)
    36May 31 11:07:47.877: //3303//MSW :/msw_synth_open: AIS : Creating TTS AIS Backend record
    37May 31 11:07:47.877: //-1//MSM :MS1314:/ms_create: Iniz ply_timer
    38May 31 11:07:47.877: //3303//MSW :/msw_recrd_open:
    39May 31 11:07:47.877: :msw_recrd_open mediaStream 0x65589ED8 created
    40May 31 11:07:47.877: //3303//MSW :/msw_recrd_open: rtspStream 0x6734BE44 created,
    41                        status=RTSP_STATUS_SUCCESS, session_id=0x522 (1314)
    42May 31 11:07:47.877: //3303//MSW :/msw_recog_open: AIS : Creating ASR AIS Backend record
    43May 31 11:07:47.877: //-1//MSW :/msw_associate_call:
    44May 31 11:07:47.877: msw_associate_call: callID=0xCE7(3303),
    45                                          genericStream=0xC0E99804
    46May 31 11:07:47.877: //3303//MSW :/msw_synth_get_stream_state: genericStream 0xC0E99804 is in state MSW_S_IDLE
    47May 31 11:07:47.877: //-1//MSW :/msw_synth_start:
    48May 31 11:07:47.877: msw_synth_start: Enter...
    49May 31 11:07:47.877: //3303//MSW :/msw_synth_start: current_stream_id=1, content 0x0, dynamicS 0x73D990F0, current_state=MSW_S_IDLE
    50May 31 11:07:47.877: //-1//MSW :/msw_synth_start: msw_synth_start: p_mcDynamicS, We've been given a list of URLs to play.
    51May 31 11:07:47.877: //-1//MSW :/msw_synth_start: p_mcDynamicQ is NOT empty
    52May 31 11:07:47.877: //3303//MSW :/msu_synth_partial_play: Media Stream URL
    53May 31 11:07:47.877: //-1//MCM :MR1289:/mc_createDynamicReader:
    54May 31 11:07:47.877: //3303//MSM :/ms_get_packet_size:
    55May 31 11:07:47.877: ms_get_packet_size NO Voice Class codec
    56May 31 11:07:47.877: //3303//MSM :/ms_associate: packet_size = 160 timestamp increment = 160 packet_duration = 20 Coder = 5 vad = 0 SampleRate = 8000
    57May 31 11:07:47.877: //3303//MSM :/ms_associate: >>ccAssociateStream()
    58May 31 11:07:47.877: //-1//TCL :EEC0EC34BC000:/tcl_PutsObjCmd: DEBUG: CALL ACTIVE true
    59May 31 11:07:47.877:
    60May 31 11:07:47.877: //-1//TCL :EEC0EC34BC000:/tcl_PutsObjCmd: DEBUG: act_CheckCallSetup stop
    61May 31 11:07:47.877:


    The call comes to external phone (05550052xx), a man replies and hear silence.
    I confused by:
    1May 31 11:07:47.877: ms_get_packet_size NO Voice Class codec


    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Raghavendra Gutty Veeranagappa on 31-05-2011 02:30:12 AM
    Hi Marat,

    you can't play media when the call is in active, you need to destroy connnection and play media file.

    Thanks,
    Raghavendra

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Marat Rabidinov on 31-05-2011 03:43:50 AM
    You don't understand me.
    Cisco make a call to external phone and must play a audio file, but it doesn't.
    Do you see my code?

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Raghavendra Gutty Veeranagappa on 31-05-2011 05:30:43 AM
    Hi Marat,

    I understand that you trying to play media file to leg_outgoing once the call setup between leg_incoming and leg_outgoing if not please explain briefly about your call flow.

    from your code found that you trying to leg setup leg_outgoing could you explain why?
    leg setup $numExt1 callinfo leg_outgoing

    and also you are trying  to play the media after leg setup done which won't work.


    Thanks,
    Raghavendra

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Marat Rabidinov on 31-05-2011 05:44:10 AM
    Ok.
    The script must call to phones and talk some information automatically.

    Plan:
    1. The script is called from terminal (CLI), as discribes in guide http://www.cisco.com/en/US/docs/ios/voice/ivr/configuration/guide/gt_tclsi.html#wp1011820
    Router#call application session start my_balance balance


    2. Script calls to phone (05550052xx)

    3. Plays a media file when the call is active between Cisco and 05550052xx

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Yaw-Ming Chen on 31-05-2011 12:37:28 PM
    Raghavendra is right. From debug I saw you got "ls_000" which is good that you made the call tio externan phone. Now outgoing leg is connected.
    But you CAN NOt play media to outgoing leg now because it's active and connected. Now you need to use "connection destroy" command first (please refer to programming guide). "connection destroy" doesn't mean to discinnect the leg, it just seperate the leg from the connection but Tcl application is holding the leg.
    After you get the"ev_destroy_done" event you can play the media to outgoing leg.
     
    Take an example,
     
    A calls B via Tcl script. When A is talking to B, Tcl script cannot inject the media. We need to "destroy" the conversation first then play media to A or B.
    Same thing applys to your case.
     
    Example in state machine,
     
     set fsm(DESTOY4MEDIA,ev_destroy_done)  "act_Destroyed4media   same_state"
     
     
    Thanks !
     
    Ok.
    The script must call to phones and talk some information automatically.

    Plan:
    1. The script is called from terminal (CLI), as discribes in guide http://www.cisco.com/en/US/docs/ios/voice/ivr/configuration/guide/gt_tclsi.html#wp1011820
    Router#call application session start my_balance balance


    2. Script calls to phone (05550052xx)

    3. Plays a media file when the call is active between Cisco and 05550052xx


    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Yaw-Ming Chen on 31-05-2011 02:11:33 PM
    I did a  quick test, in you case you might be able to skip the "connection destroy" so the problem might be media.
    My suggestion is that load the media directly
    use
    " media play leg_outgoing flash: ru_welcome.au" or  " media play leg_outgoing flash: ru_welcome.au" or  " media play leg_outgoing tftp://xxx.xxx.xxx.xxx ru_welcome.au" ...etc.


    This is what I have and it's working for me.


    proc init { } {
        global dest
        global myPrompt
       
          if [infotag get cfg_avpair_exists my-prompt] {
                set myPrompt [string trim [infotag get cfg_avpair my-prompt]]
           
            } else {
                set myPrompt flash:en_welcome.au
           
            }
       
    }



    proc act_Setup { } {
        global dest

        set dest 1008
        set callInfo(notifyEvents) "ev_alert ev_progress ev_proceeding ev_connected"
       
        puts "New DEST is $dest\n"
       
        leg setup $dest callInfo
       
        fsm setstate PLACECALL   
    }


    proc act_CallSetupDone { } {

      global myPrompt    


        set status [infotag get evt_status]
     
        if { $status == "ls_000"} {
      
            puts "event status $status\n"
             media play leg_outgoing $myPrompt
        } else {
            puts "Call [infotag get con_all] got event $status collecting destination\n"
            call close
        }
    }




    proc act_Cleanup { } {
        call close
    }

    requiredversion 2.0
    init


    #----------------------------------
    #   State Machine
    #----------------------------------
      set fsm(any_state,ev_disconnected)    "act_Cleanup   same_state"
      set fsm(CALL_INIT,ev_session_indication)  "act_Setup             same_state"
     
      set fsm(PLACECALL,ev_setup_done)      "act_CallSetupDone     CALLACTIVE"
      set fsm(CALLACTIVE,ev_media_done)             "act_Cleanup            CALLDISCONNECT"
      set fsm(CALLACTIVE,ev_disconnected)    "act_Cleanup          CALLDISCONNECT"
      set fsm(CALLDISCONNECT,ev_disconnected)    "act_Cleanup          same_state"
      set fsm(CALLDISCONNECT,ev_disconnect_done)  "act_Cleanup          same_state"

      fsm define fsm CALL_INIT

    Subject: RE: How to make a call to external phone and play a media file
    Replied by: Marat Rabidinov on 01-06-2011 11:02:32 PM
    Thanks all!
    I changed a media file, and it is played to 05550052xx.
    But in a several time running this script, I got again a silence and a error:
    1ms_get_packet_size NO Voice Class codec
    .
    If I change a name of media file, 05550052xx can hear it again for several time.