Exemple #1
0
int setSynthesizer(char* synth)
{
#ifdef _WIN32
	int s = atoi(synth);
	return sapisetvoice(s);
#else
	return spd_set_synthesis_voice(conn, synth);
#endif
}
Exemple #2
0
int main()
{
	SPDConnection *conn;
	int i, j, ret;
	char **modules;
	char **voices;
	SPDVoice **synth_voices;

	printf("Start of the test.\n");

	printf("Trying to initialize Speech Deamon...");
	conn = spd_open("say", NULL, NULL, SPD_MODE_SINGLE);
	if (conn == 0) {
		printf("Speech Deamon failed");
		exit(1);
	}
	printf("OK\n");

	modules = spd_list_modules(conn);
	if (modules == NULL) {
		printf("Can't list modules\n");
		exit(1);
	}

	printf("Available output modules:\n");
	for (i = 0;; i++) {
		if (modules[i] == NULL)
			break;
		printf("     %s\n", modules[i]);
	}

	voices = spd_list_voices(conn);
	if (voices == NULL) {
		printf("Can't list voices\n");
		exit(1);
	}

	printf("Available symbolic voices:\n");
	for (i = 0;; i++) {
		if (voices[i] == NULL)
			break;
		printf("     %s\n", voices[i]);
	}

	for (j = 0;; j++) {
		if (modules[j] == NULL)
			break;
		ret = spd_set_output_module(conn, modules[j]);
		if (ret == -1) {
			printf("spd_set_output_module failed");
			exit(1);
		}
		printf("\nListing voices for %s\n", modules[j]);
		synth_voices = spd_list_synthesis_voices(conn);
		if (synth_voices == NULL) {
			printf("Can't list voices\n");
			exit(1);
		}
		printf("Available synthesis voices:\n");
		for (i = 0;; i++) {
			if (synth_voices[i] == NULL)
				break;
			printf("     name: %s language: %s variant: %s\n",
			       synth_voices[i]->name, synth_voices[i]->language,
			       synth_voices[i]->variant);
			ret =
			    spd_set_synthesis_voice(conn,
						    synth_voices[i]->name);
			if (ret == -1) {
				printf("spd_set_synthesis_voice failed");
				exit(1);
			}

			ret = spd_say(conn, SPD_TEXT, "test");
			if (ret == -1) {
				printf("spd_say failed");
				exit(1);
			}
			sleep(1);
		}
	}

	printf("Trying to close Speech Dispatcher connection...");
	spd_close(conn);
	printf("OK\n");

	printf("End of the test.\n");
	exit(0);
}
Exemple #3
0
int main(int argc, char **argv)
{
	SPDConnection *conn;
	SPDPriority spd_priority;
	int err;
	int ret;
	int msg_arg_required = 0;
	int option_ret;
	char *line;

	/* init i18n support */
	setlocale(LC_ALL,"");
	bindtextdomain(GETTEXT_PACKAGE,LOCALEDIR);
	textdomain(GETTEXT_PACKAGE);

	language = NULL;
	voice_type = NULL;
	punctuation_mode = NULL;
	wait_till_end = 0;
	stop_previous = 0;
	cancel_previous = 0;
	pipe_mode = 0;
	priority = NULL;
	application_name = NULL;
	connection_name = NULL;

	option_ret = options_parse(argc, argv);

	/* Check if the text to say or options are specified in the argument */
	msg_arg_required = (pipe_mode != 1) && (stop_previous != 1)
	    && (cancel_previous != 1) && (list_synthesis_voices != 1)
	    && (list_output_modules != 1);
	if ((optind >= argc) && msg_arg_required) {
		/*
		 * We require a message on the command-line, but there
		 * are no arguments.
		 */
		options_print_help(argv);
		return 1;
	}

	/* Open a connection to openttsd */
	conn = spd_open(application_name ? application_name : "otts-say",
			connection_name ? connection_name : "main",
			NULL, SPD_MODE_THREADED);
	if (conn == NULL)
		FATAL("openttsd failed to open");

	if (stop_previous)
		spd_stop_all(conn);
	if (cancel_previous)
		spd_cancel_all(conn);

	/* Set the desired parameters */

	if (language != NULL)
		if (spd_set_language(conn, language))
			printf(_("Invalid language!\n"));

	if (output_module != NULL)
		if (spd_set_output_module(conn, output_module))
			printf(_("Invalid output module!\n"));

	if (list_output_modules) {
		char **list;
		int i;

		list = spd_list_modules(conn);

		if (list != NULL) {
			printf (_("OUTPUT MODULES\n"));
			for (i = 0; list[i]; i++) {
				printf ("%s\n",list[i]);
			}
		} else {
			printf(_("Output modules not found.\n"));
		}
	}

	if (voice_type != NULL) {
		if (!strcmp(voice_type, "male1")) {
			if (spd_set_voice_type(conn, SPD_MALE1))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "male2")) {
			if (spd_set_voice_type(conn, SPD_MALE2))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "male3")) {
			if (spd_set_voice_type(conn, SPD_MALE3))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female1")) {
			if (spd_set_voice_type(conn, SPD_FEMALE1))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female2")) {
			if (spd_set_voice_type(conn, SPD_FEMALE2))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female3")) {
			if (spd_set_voice_type(conn, SPD_FEMALE3))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "child_male")) {
			if (spd_set_voice_type(conn, SPD_CHILD_MALE))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "child_female")) {
			if (spd_set_voice_type(conn, SPD_CHILD_FEMALE))
				printf("Can't set this voice!\n");
		} else {
			printf("Invalid voice\n");
		}
	}

	if (list_synthesis_voices) {
		SPDVoice **list;
		int i;

		list = spd_list_synthesis_voices(conn);
		if (list != NULL) {
			printf ("%25s%25s%25s\n","NAME", "LANGUAGE", "VARIANT");
			for (i = 0; list[i]; i++) {
				printf ("%25s%25s%25s\n",
					list[i]->name,
					list[i]->language,
					list[i]->variant);
			}
		} else {
			printf(_("Failed to get voice list.\n"));
		}
	}

	if (synthesis_voice != NULL)
		if (spd_set_synthesis_voice(conn, synthesis_voice))
			printf(_("Failed to set synthesis voice!\n"));

	if (data_mode != SPD_DATA_TEXT)
		if (spd_set_data_mode(conn, data_mode))
			printf(_("Failed to set SSML mode.\n"));

	if (rate != OTTS_VOICE_RATE_DEFAULT)
		if (spd_set_voice_rate(conn, rate))
			printf(_("Invalid rate!\n"));

	if (pitch != OTTS_VOICE_PITCH_DEFAULT)
		if (spd_set_voice_pitch(conn, pitch))
			printf(_("Invalid pitch!\n"));

	if (volume != OTTS_VOICE_VOLUME_DEFAULT)
		if (spd_set_volume(conn, volume))
			printf(_("Invalid volume!\n"));

	if (spelling != SPD_SPELL_OFF)
		if (spd_set_spelling(conn, spelling))
			printf(_("Can't enable spelling!\n"));

	if (punctuation_mode != NULL) {
		if (!strcmp(punctuation_mode, "none")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_NONE))
				printf("Can't set this punctuation mode!\n");
		} else if (!strcmp(punctuation_mode, "some")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_SOME))
				printf("Can't set this punctuation mode!\n");
		} else if (!strcmp(punctuation_mode, "all")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_ALL))
				printf("Can't set this punctuation mode!\n");
		} else {
			printf("Invalid punctuation mode.\n");
		}
	}

	/* Set default priority... */
	if (pipe_mode == 1)
		spd_priority = SPD_MESSAGE;
	else
		spd_priority = SPD_TEXT;
	/* ...and be sure it wasn't overridden */
	if (priority != NULL) {
		if (!strcmp(priority, "important"))
			spd_priority = SPD_IMPORTANT;
		else if (!strcmp(priority, "message"))
			spd_priority = SPD_MESSAGE;
		else if (!strcmp(priority, "text"))
			spd_priority = SPD_TEXT;
		else if (!strcmp(priority, "notification"))
			spd_priority = SPD_NOTIFICATION;
		else if (!strcmp(priority, "progress"))
			spd_priority = SPD_PROGRESS;
		else {
			printf(_("Invalid priority.\n"));
		}
	}

	if (wait_till_end) {
		ret = sem_init(&semaphore, 0, 0);
		if (ret < 0) {
			fprintf(stderr, "Can't initialize semaphore: %s",
				strerror(errno));
			return 0;
		}

		/* Notify when the message is canceled or the speech terminates */
		conn->callback_end = end_of_speech;
		conn->callback_cancel = end_of_speech;
		spd_set_notification_on(conn, SPD_END);
		spd_set_notification_on(conn, SPD_CANCEL);
	}

	/* In pipe mode, read from stdin, write to stdout, and also to openttsd. */
	if (pipe_mode == 1) {
		line = (char *)malloc(MAX_LINELEN);
		while (fgets(line, MAX_LINELEN, stdin) != NULL) {
			fputs(line, stdout);
			if (strncmp(line, "!-!", 3) == 0) {
				/* Remove EOL */
				line[strlen(line) - 1] = 0;
				spd_execute_command(conn, line + 3);
			} else {
				spd_say(conn, spd_priority, line);
				if (wait_till_end)
					sem_wait(&semaphore);
			}
		}
		free(line);
	} else {
		/* Say the message with priority "text" */
		/* Or do nothing in case of -C or -S with no message. */
		if (optind < argc) {
			err = spd_sayf(conn, spd_priority, (char *)argv[optind]);
			if (err == -1)
				FATAL("openttsd failed to say message");

			/* Wait till the callback is called */
			if (wait_till_end)
				sem_wait(&semaphore);
		}
	}

	/* Close the connection */
	spd_close(conn);

	return 0;
}