/** Create demo synthesizer channel derived from engine channel base */ static mrcp_engine_channel_t* mrcp_swift_engine_channel_create(mrcp_resource_engine_t *engine, apr_pool_t *pool) { swift_engine *synth_engine = engine->obj; mrcp_swift_channel_t *synth_channel; mrcp_engine_channel_t *channel; swift_params *params; swift_port *port; mpf_codec_descriptor_t *codec_descriptor; codec_descriptor = apr_palloc(pool,sizeof(mpf_codec_descriptor_t)); mpf_codec_descriptor_init(codec_descriptor); codec_descriptor->channel_count = 1; codec_descriptor->payload_type = 96; apt_string_set(&codec_descriptor->name,"L16"); codec_descriptor->sampling_rate = 8000; params = swift_params_new(NULL); swift_params_set_string(params, "audio/encoding", "pcm16"); swift_params_set_int(params, "audio/sampling-rate", codec_descriptor->sampling_rate); /* open swift port */ apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Open Swift Port"); if((port = swift_port_open(synth_engine,params)) == NULL) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Open Swift Port"); return NULL; } /* create swift synth channel */ synth_channel = apr_palloc(pool,sizeof(mrcp_swift_channel_t)); synth_channel->speak_request = NULL; synth_channel->stop_response = NULL; synth_channel->paused = FALSE; synth_channel->channel = NULL; synth_channel->port = port; synth_channel->tts_stream = 0; /* create engine channel base */ channel = mrcp_engine_source_channel_create( engine, /* resource engine */ &channel_vtable, /* virtual methods table of engine channel */ &audio_stream_vtable, /* virtual methods table of audio stream */ synth_channel, /* object to associate */ codec_descriptor, /* codec descriptor might be NULL by default */ pool); /* pool to allocate memory from */ if(!channel) { swift_port_close(port); synth_channel->port = NULL; return NULL; } synth_channel->audio_buffer = mpf_buffer_create(pool); /* set swift_write_audio as a callback, with the output file as its param */ swift_port_set_callback(port, &mrcp_swift_write_audio, SWIFT_EVENT_AUDIO | SWIFT_EVENT_END, synth_channel); synth_channel->channel = channel; return channel; }
mpf_codec_descriptor_t* mpf_codec_lpcm_descriptor_create(apr_uint16_t sampling_rate, apr_byte_t channel_count, apr_pool_t *pool) { mpf_codec_descriptor_t *descriptor = apr_palloc(pool,sizeof(mpf_codec_descriptor_t)); mpf_codec_descriptor_init(descriptor); descriptor->payload_type = 96; descriptor->name.buf = LPCM_CODEC_NAME; descriptor->name.length = LPCM_CODEC_NAME_LENGTH; descriptor->sampling_rate = sampling_rate; descriptor->channel_count = channel_count; return descriptor; }
MPF_DECLARE(mpf_codec_descriptor_t*) mpf_event_descriptor_create(apr_uint16_t sampling_rate, apr_pool_t *pool) { mpf_codec_descriptor_t *descriptor = apr_palloc(pool,sizeof(mpf_codec_descriptor_t)); mpf_codec_descriptor_init(descriptor); descriptor->payload_type = 101; descriptor->name.buf = TEL_EVENT_NAME; descriptor->name.length = TEL_EVENT_NAME_LENGTH; descriptor->sampling_rate = sampling_rate; descriptor->channel_count = 1; descriptor->format.buf = TEL_EVENT_FMTP; descriptor->format.length = TEL_EVENT_FMTP_LENGTH; return descriptor; }
static mpf_codec_t* mpf_termination_default_codec_create(mpf_termination_t *termination) { mpf_codec_t *codec; const mpf_codec_descriptor_t *default_descriptor = l16_descriptor_get(); mpf_codec_descriptor_t *descriptor = apr_palloc(termination->pool,sizeof(mpf_codec_descriptor_t)); mpf_codec_descriptor_init(descriptor); *descriptor = *default_descriptor; codec = mpf_codec_manager_codec_get( termination->codec_manager, descriptor, termination->pool); return codec; }