Example #1
0
/** Open engine channel (asynchronous response MUST be sent)*/
static apt_bool_t mrcp_swift_channel_open(mrcp_engine_channel_t *channel)
{
	/* open channel and send asynch response */
	apt_bool_t status = FALSE;
	mrcp_swift_channel_t *synth_channel = channel->method_obj;
	mrcp_swift_engine_t *synth_engine = channel->engine->obj;
	const mpf_codec_descriptor_t *descriptor = mrcp_engine_source_stream_codec_get(synth_channel->channel);
	if(descriptor) {
		swift_params *params;
		swift_port *port;

		params = swift_params_new(NULL);
		swift_params_set_string(params, "audio/encoding", "pcm16");
		swift_params_set_int(params, "audio/sampling-rate", descriptor->sampling_rate);
		/* open swift port */ 
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Open Swift Port");
		port = swift_port_open(synth_engine->swift,params);
		if(port) {
			/* 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->port = port;
			status = TRUE;
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Open Swift Port");
		}
	}

	return mrcp_engine_channel_open_respond(channel,status);
}
Example #2
0
/** 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;
}