/** 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; }
/** Create demo synthesizer channel derived from engine channel base */ static mrcp_engine_channel_t* mrcp_swift_engine_channel_create(mrcp_engine_t *engine, apr_pool_t *pool) { mrcp_swift_engine_t *synth_engine = engine->obj; mpf_stream_capabilities_t *capabilities; mpf_termination_t *termination; mrcp_engine_channel_t *channel; /* create swift synth channel */ mrcp_swift_channel_t *synth_channel = apr_palloc(pool,sizeof(mrcp_swift_channel_t)); synth_channel->port = NULL; synth_channel->tts_stream = 0; synth_channel->channel = NULL; synth_channel->audio_buffer = NULL; synth_channel->speak_request = NULL; synth_channel->stop_response = NULL; synth_channel->paused = FALSE; capabilities = mpf_source_stream_capabilities_create(pool); mpf_codec_capabilities_add( &capabilities->codecs, synth_engine->sample_rates, "LPCM"); /* create media termination */ termination = mrcp_engine_audio_termination_create( synth_channel, /* object to associate */ &audio_stream_vtable, /* virtual methods table of audio stream */ capabilities, /* stream capabilities */ pool); /* pool to allocate memory from */ /* create engine channel base */ channel = mrcp_engine_channel_create( engine, /* engine */ &channel_vtable, /* virtual methods table of engine channel */ synth_channel, /* object to associate */ termination, /* associated media termination */ pool); /* pool to allocate memory from */ if(channel) { synth_channel->audio_buffer = mpf_buffer_create(pool); } synth_channel->channel = channel; return channel; }