static switch_status_t tts_commandline_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
	switch_status_t ret=SWITCH_STATUS_SUCCESS;
	char *message, *tmp, *mtmp, *rate;
	tts_commandline_t *info = (tts_commandline_t *) sh->private_info;

	assert(info != NULL);

	if (switch_test_flag(info->fh, SWITCH_FILE_OPEN)) {
		switch_core_file_close(info->fh);
		unlink(info->file);
	}

	tmp = switch_util_quote_shell_arg(text);
	message = switch_string_replace(globals.command, "${text}", tmp);
	switch_safe_free(tmp); mtmp=message;

	tmp = switch_util_quote_shell_arg(info->voice_name);
	message = switch_string_replace(mtmp, "${voice}", tmp);
	switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message;

	rate = switch_core_sprintf(sh->memory_pool, "%d", info->rate);
	message = switch_string_replace(mtmp, "${rate}", rate);
	switch_safe_free(mtmp); mtmp=message;

	tmp = switch_util_quote_shell_arg(info->file);
	message = switch_string_replace(mtmp, "${file}", tmp);
	switch_safe_free(tmp); switch_safe_free(mtmp); mtmp=message;

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing: %s\n", message);

	if (switch_system(message, SWITCH_TRUE) < 0) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute command: %s\n", message);
		ret = SWITCH_STATUS_FALSE; goto done;
	}

	if (switch_core_file_open(info->fh, info->file, 0,	//number_of_channels,
							  info->rate,	//samples_per_second,
							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file: %s\n", info->file);
		ret = SWITCH_STATUS_FALSE; goto done;
	}

	sh->private_info = info;

 done:
	switch_safe_free(mtmp);
	return ret;
}
Beispiel #2
0
void *SWITCH_THREAD_FUNC monitor_thread_run(switch_thread_t *thread, void *obj)
{
	xml_binding_t *binding = (xml_binding_t *) obj;
	time_t st;
	int diff;

	while(globals.running) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Running server command: %s\n", binding->server);
		st = switch_epoch_time_now(NULL);
		switch_system(binding->server, SWITCH_TRUE);
		diff = (int) switch_epoch_time_now(NULL) - st;
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server command complete: %s\n", binding->server);

		if (globals.running && diff < 5) {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server command had short run duration, sleeping: %s\n", binding->server);
			switch_yield(10000000);
		}
	}
	
	return NULL;
}