コード例 #1
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_cancel_uid(SPDConnection *connection, int target_uid)
{
  static char command[16];

  sprintf(command, "CANCEL %d", target_uid);
  return spd_execute_command(connection, command);
}
コード例 #2
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_stop_uid(SPDConnection *connection, int target_uid)
{
  static char command[16];

  sprintf(command, "STOP %d", target_uid);
  return spd_execute_command(connection, command);
}
コード例 #3
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_resume_uid(SPDConnection *connection, int target_uid)
{
  static char command[16];

  sprintf(command, "RESUME %d", target_uid);
  return spd_execute_command(connection, command);
}
コード例 #4
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_pause_uid(SPDConnection *connection, int target_uid)
{
  char command[16];

  sprintf(command, "PAUSE %d", target_uid);
  return spd_execute_command(connection, command);
}
コード例 #5
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_w_set_spelling(SPDConnection *connection, SPDSpelling type, const char* who)
{
    char command[32];
    int ret;

    if (type == SPD_SPELL_ON)
        sprintf(command, "SET %s SPELLING on", who);
    if (type == SPD_SPELL_OFF)
        sprintf(command, "SET %s SPELLING off", who);

    ret = spd_execute_command(connection, command);

    return ret;
}
コード例 #6
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_set_data_mode(SPDConnection *connection, SPDDataMode mode)
{
    char command[32];
    int ret;

    if (mode == SPD_DATA_TEXT)
        sprintf(command, "SET SELF SSML_MODE off");
    if (mode == SPD_DATA_SSML)
        sprintf(command, "SET SELF SSML_MODE on");

    ret = spd_execute_command(connection, command);

    return ret;
}
コード例 #7
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_w_set_punctuation(SPDConnection *connection, SPDPunctuation type, const char* who)
{
    char command[32];
    int ret;

    if (type == SPD_PUNCT_ALL)
        sprintf(command, "SET %s PUNCTUATION all", who);
    if (type == SPD_PUNCT_NONE)
        sprintf(command, "SET %s PUNCTUATION none", who);
    if (type == SPD_PUNCT_SOME)
        sprintf(command, "SET %s PUNCTUATION some", who);

    ret = spd_execute_command(connection, command);    
    
    return ret;
}
コード例 #8
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_w_set_capital_letters(SPDConnection *connection, SPDCapitalLetters type, const char* who)
{
    char command[64];
    int ret;

    if (type == SPD_CAP_NONE)
        sprintf(command, "SET %s CAP_LET_RECOGN none", who);
    if (type == SPD_CAP_SPELL)
        sprintf(command, "SET %s CAP_LET_RECOGN spell", who);
    if (type == SPD_CAP_ICON)
        sprintf(command, "SET %s CAP_LET_RECOGN icon", who);

    ret = spd_execute_command(connection, command);    
    
    return ret;
}
コード例 #9
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_w_set_voice_type(SPDConnection *connection, SPDVoiceType type, const char *who)
{
    static char command[64];

    switch(type){
    case SPD_MALE1: sprintf(command, "SET %s VOICE MALE1", who); break;
    case SPD_MALE2: sprintf(command, "SET %s VOICE MALE2", who); break;
    case SPD_MALE3: sprintf(command, "SET %s VOICE MALE3", who); break;
    case SPD_FEMALE1: sprintf(command, "SET %s VOICE FEMALE1", who); break;
    case SPD_FEMALE2: sprintf(command, "SET %s VOICE FEMALE2", who); break;
    case SPD_FEMALE3: sprintf(command, "SET %s VOICE FEMALE3", who); break;
    case SPD_CHILD_MALE: sprintf(command, "SET %s VOICE CHILD_MALE", who); break;
    case SPD_CHILD_FEMALE: sprintf(command, "SET %s VOICE CHILD_FEMALE", who); break;
    default: return -1;
    }
    
    return spd_execute_command(connection, command);      
}
コード例 #10
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_resume(SPDConnection *connection)
{
  return spd_execute_command(connection, "RESUME SELF");
}
コード例 #11
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_cancel_all(SPDConnection *connection)
{
  return spd_execute_command(connection, "CANCEL ALL");
}
コード例 #12
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_cancel(SPDConnection *connection)
{
  return spd_execute_command(connection, "CANCEL SELF");
}
コード例 #13
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_pause(SPDConnection *connection)
{
  return spd_execute_command(connection, "PAUSE SELF");
}
コード例 #14
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_pause_all(SPDConnection *connection)
{
  return spd_execute_command(connection, "PAUSE ALL");
}
コード例 #15
0
ファイル: say.c プロジェクト: razr/opentts
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;
}
コード例 #16
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_resume_all(SPDConnection *connection)
{
  return spd_execute_command(connection, "RESUME ALL");
}
コード例 #17
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_stop_all(SPDConnection *connection)
{
  return spd_execute_command(connection, "STOP ALL");
}
コード例 #18
0
ファイル: say.c プロジェクト: FREEWING-JP/ekho
int main(int argc, char **argv) {
    SPDConnection *conn;
    SPDPriority spd_priority;
    int err;
    char *error;
    int msg_arg_required = 0;
    int ret;
    int option_ret;
    char *line;

    rate = -101;
    pitch = -101;
    volume = -101;
    language = NULL;
    voice_type = NULL;
    punctuation_mode = NULL;
    spelling = -2;
    ssml_mode = 0;
    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);
    if ((optind >= argc) && msg_arg_required) {
        options_print_help(argv);
        return 1;
    }

    /* Open a connection to Speech Dispatcher */
    conn = spd_open2(application_name ? application_name : "spd-say",
                    connection_name ? connection_name : "main",
		     NULL, SPD_MODE_THREADED, NULL, 1, &error);
    if (conn == NULL){
      fprintf(stderr, "Failed to connect to Speech Dispatcher:\n%s\n", error);
      exit(1);
    }

    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 (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 (ssml_mode)
        if(spd_execute_command(conn, "SET SELF SSML_MODE ON"))
            printf("Failed to set SSML mode.\n");

    if (rate != -101)
        if(spd_set_voice_rate(conn, rate))
            printf("Invalid rate!\n");

    if (pitch != -101)
        if(spd_set_voice_pitch(conn, pitch))
            printf("Invalid pitch!\n");

    if (volume != -101)
        if(spd_set_volume(conn, volume))
            printf("Invalid volume!\n");

    if (spelling == 1)
        if(spd_set_spelling(conn, SPD_SPELL_ON))
            printf("Can't set spelling to on!\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 (1 == pipe_mode)
        spd_priority = SPD_MESSAGE;
    else
        spd_priority = SPD_TEXT;
    /* ...and look if it wasn't overriden */
    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 Speech Dispatcher. */
    if (pipe_mode == 1) {
        line = (char *) malloc( MAX_LINELEN );
        while (NULL != fgets(line, MAX_LINELEN, stdin)) {
            fputs(line, stdout);
            if (0 == strncmp(line, "!-!", 3)) {
                /* 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){
	    fprintf(stderr, "Speech Dispatcher failed to say message");
	    exit(1);
	  }

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

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

    return 0;
}
コード例 #19
0
ファイル: libspeechd.c プロジェクト: FREEWING-JP/ekho
int
spd_stop(SPDConnection *connection)
{
  return spd_execute_command(connection, "STOP SELF");
}