1. 程式人生 > >PJSIP自動語音功能,WAV檔案遠端播放,可以與TTS整合

PJSIP自動語音功能,WAV檔案遠端播放,可以與TTS整合

使用PJSIP進行自動語音功能,卡了好久,最終發現其實還是比較簡單的。

PJSIP就是比較強大,很多都實現好了,都不需要去很深地瞭解協議。

說實在的話,我就不瞭解SIP協議的細節。

PJSUA has rather powerful media features, which are built around the PJMEDIA conference bridge. Basically, all media "ports" (such as calls, WAV players, WAV playlist, file recorders, sound device, tone generators, etc) are terminated in the conference bridge, and application can manipulate the interconnection between these terminations freely.

The conference bridge provides powerful switching and mixing functionality for application. With the conference bridge, each conference slot (e.g. a call) can transmit to multiple destinations, and one destination can receive from multiple sources. If more than one media terminations are terminated in the same slot, the conference bridge will mix the signal automatically.

Application connects one media termination/slot to another by calling pjsua_conf_connect() function. This will establish unidirectional media flow from the source termination to the sink termination. To establish bidirectional media flow, application wound need to make another call to pjsua_conf_connect(), this time inverting the source and destination slots in the parameter.

For example, to stream a WAV file to remote call, application may use the following steps:

  pj_status_t stream_to_call( pjsua_call_id call_id )

  {

     pjsua_player_id player_id;

     status = pjsua_player_create("mysong.wav", 0, NULL, &player_id);

     if (status != PJ_SUCCESS)

        return status;

     status = pjsua_conf_connect( pjsua_player_get_conf_port(),

                                  pjsua_call_get_conf_port() );

  }

Other features of PJSUA media:

efficient N to M interconnections between media terminations. 

media termination can be connected to itself to create loopback media. 

the media termination may have different clock rates, and resampling will be done automatically by conference bridge. 

media terminations may also have different frame time; the conference bridge will perform the necessary bufferring to adjust the difference between terminations. 

interconnections are removed automatically when media termination is removed from the bridge. 

sound device may be changed even when there are active media interconnections. 

correctly report call's media quality (in pjsua_call_dump()) from RTCP packet exchange.