[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/4] use SPDMsgSettings in TFDSetElement
From: |
Andrei Kholodnyi |
Subject: |
[PATCH 3/4] use SPDMsgSettings in TFDSetElement |
Date: |
Wed, 27 Oct 2010 17:15:20 +0200 |
group variables into SPDMsgSettings in TFDSetElement
move SPDMsgSettings from module_utils.h to speechd_types.h
since now it is used in server as well
---
include/speechd_types.h | 13 +++++++
src/modules/module_utils.h | 13 -------
src/server/alloc.c | 8 ++--
src/server/configuration.c | 48 ++++++++++++------------
src/server/output.c | 33 +++++++++++++----
src/server/parse.c | 2 +-
src/server/server.c | 4 +-
src/server/set.c | 84 ++++++++++++++++++++++---------------------
src/server/speechd.h | 13 +------
9 files changed, 114 insertions(+), 104 deletions(-)
diff --git a/include/speechd_types.h b/include/speechd_types.h
index 66bc9a4..fc68783 100644
--- a/include/speechd_types.h
+++ b/include/speechd_types.h
@@ -105,4 +105,17 @@ typedef enum {
SPD_MSGTYPE_SPELL = 99
} SPDMessageType;
+typedef struct {
+ signed int rate;
+ signed int pitch;
+ signed int volume;
+
+ SPDPunctuation punctuation_mode;
+ SPDSpelling spelling_mode;
+ SPDCapitalLetters cap_let_recogn;
+
+ SPDVoiceType voice_type;
+ SPDVoice voice;
+} SPDMsgSettings;
+
#endif /* not ifndef SPEECHD_TYPES */
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index 91ff2bd..e13d74b 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -47,19 +47,6 @@
#include <speechd_types.h>
#include "spd_audio.h"
-typedef struct{
- signed int rate;
- signed int pitch;
- signed int volume;
-
- SPDPunctuation punctuation_mode;
- SPDSpelling spelling_mode;
- SPDCapitalLetters cap_let_recogn;
-
- SPDVoiceType voice_type;
- SPDVoice voice;
-}SPDMsgSettings;
-
int log_level;
AudioID *module_audio_id;
diff --git a/src/server/alloc.c b/src/server/alloc.c
index 4bb9226..92a978a 100644
--- a/src/server/alloc.c
+++ b/src/server/alloc.c
@@ -11,8 +11,8 @@ spd_fdset_copy(TFDSetElement old)
TFDSetElement new;
new = old;
- new.language = g_strdup(old.language);
- new.synthesis_voice = g_strdup(old.synthesis_voice);
+ new.msg_settings.voice.language =
g_strdup(old.msg_settings.voice.language);
+ new.msg_settings.voice.name = g_strdup(old.msg_settings.voice.name);
new.client_name = g_strdup(old.client_name);
new.output_module = g_strdup(old.output_module);
new.index_mark = g_strdup(old.index_mark);
@@ -51,8 +51,8 @@ mem_free_fdset(TFDSetElement *fdset)
/* Don't forget that only these items are filled in
in a TSpeechDMessage */
g_free(fdset->client_name);
- g_free(fdset->language);
- g_free(fdset->synthesis_voice);
+ g_free(fdset->msg_settings.voice.language);
+ g_free(fdset->msg_settings.voice.name);
g_free(fdset->output_module);
g_free(fdset->index_mark);
g_free(fdset->audio_output_method);
diff --git a/src/server/configuration.c b/src/server/configuration.c
index 262dfe8..0bb2092 100644
--- a/src/server/configuration.c
+++ b/src/server/configuration.c
@@ -171,7 +171,7 @@ free_config_options(configoption_t *opts, int *num)
/* == CALLBACK DEFINITIONS == */
GLOBAL_FDSET_OPTION_CB_STR(DefaultModule, output_module)
-GLOBAL_FDSET_OPTION_CB_STR(DefaultLanguage, language)
+GLOBAL_FDSET_OPTION_CB_STR(DefaultLanguage, msg_settings.voice.language)
GLOBAL_FDSET_OPTION_CB_STR(DefaultClientName, client_name)
GLOBAL_FDSET_OPTION_CB_STR(AudioOutputMethod, audio_output_method)
@@ -181,16 +181,16 @@ GLOBAL_FDSET_OPTION_CB_STR(AudioNASServer,
audio_nas_server)
GLOBAL_FDSET_OPTION_CB_STR(AudioPulseServer, audio_pulse_server)
GLOBAL_FDSET_OPTION_CB_INT(AudioPulseMinLength, audio_pulse_min_length, 1, "")
-GLOBAL_FDSET_OPTION_CB_INT(DefaultRate, rate, (val>=-100)&&(val<=+100), "Rate
out of range.")
-GLOBAL_FDSET_OPTION_CB_INT(DefaultPitch, pitch, (val>=-100)&&(val<=+100),
"Pitch out of range.")
-GLOBAL_FDSET_OPTION_CB_INT(DefaultVolume, volume, (val>=-100)&&(val<=+100),
"Volume out of range.")
-GLOBAL_FDSET_OPTION_CB_INT(DefaultSpelling, spelling_mode, 1, "Invalid
spelling mode")
+GLOBAL_FDSET_OPTION_CB_INT(DefaultRate, msg_settings.rate,
(val>=-100)&&(val<=+100), "Rate out of range.")
+GLOBAL_FDSET_OPTION_CB_INT(DefaultPitch, msg_settings.pitch,
(val>=-100)&&(val<=+100), "Pitch out of range.")
+GLOBAL_FDSET_OPTION_CB_INT(DefaultVolume, msg_settings.volume,
(val>=-100)&&(val<=+100), "Volume out of range.")
+GLOBAL_FDSET_OPTION_CB_INT(DefaultSpelling, msg_settings.spelling_mode, 1,
"Invalid spelling mode")
GLOBAL_FDSET_OPTION_CB_INT(DefaultPauseContext, pause_context, 1, "")
GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPriority, priority, SPDPriority,
str2intpriority)
-GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultVoiceType, voice, SPDVoiceType,
str2EVoice)
-GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPunctuationMode, punctuation_mode,
SPDPunctuation, str2EPunctMode)
-GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultCapLetRecognition, cap_let_recogn,
SPDCapitalLetters, str2ECapLetRecogn)
+GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultVoiceType, msg_settings.voice_type,
SPDVoiceType, str2EVoice)
+GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultPunctuationMode,
msg_settings.punctuation_mode, SPDPunctuation, str2EPunctMode)
+GLOBAL_FDSET_OPTION_CB_SPECIAL(DefaultCapLetRecognition,
msg_settings.cap_let_recogn, SPDCapitalLetters, str2ECapLetRecogn)
SPEECHD_OPTION_CB_STR_M(CommunicationMethod, communication_method)
SPEECHD_OPTION_CB_STR_M(SocketPath, socket_path)
@@ -331,16 +331,16 @@ DOTCONF_CB(cb_BeginClient)
MSG(4, "Reading configuration for pattern %s", cl_spec->pattern);
/* Warning: If you modify this, you must also modify update_cl_settings()
in set.c !*/
- SET_PAR(rate, -101)
- SET_PAR(pitch, -101)
- SET_PAR(volume, -101)
- SET_PAR(punctuation_mode, -1)
- SET_PAR(spelling_mode, -1)
- SET_PAR(voice, -1)
- SET_PAR(cap_let_recogn, -1)
+ SET_PAR(msg_settings.rate, -101)
+ SET_PAR(msg_settings.pitch, -101)
+ SET_PAR(msg_settings.volume, -101)
+ SET_PAR(msg_settings.punctuation_mode, -1)
+ SET_PAR(msg_settings.spelling_mode, -1)
+ SET_PAR(msg_settings.voice_type, -1)
+ SET_PAR(msg_settings.cap_let_recogn, -1)
SET_PAR(pause_context, -1);
SET_PAR(ssml_mode, -1);
- SET_PAR_STR(language)
+ SET_PAR_STR(msg_settings.voice.language)
SET_PAR_STR(output_module)
return NULL;
@@ -440,16 +440,16 @@ void
load_default_global_set_options()
{
GlobalFDSet.priority = SPD_MESSAGE;
- GlobalFDSet.punctuation_mode = SPD_PUNCT_NONE;
- GlobalFDSet.spelling_mode = 0;
- GlobalFDSet.rate = 0;
- GlobalFDSet.pitch = 0;
- GlobalFDSet.volume = 0;
+ GlobalFDSet.msg_settings.punctuation_mode = SPD_PUNCT_NONE;
+ GlobalFDSet.msg_settings.spelling_mode = 0;
+ GlobalFDSet.msg_settings.rate = 0;
+ GlobalFDSet.msg_settings.pitch = 0;
+ GlobalFDSet.msg_settings.volume = 0;
GlobalFDSet.client_name = g_strdup("unknown:unknown:unknown");
- GlobalFDSet.language = g_strdup("en");
+ GlobalFDSet.msg_settings.voice.language = g_strdup("en");
GlobalFDSet.output_module = NULL;
- GlobalFDSet.voice = SPD_MALE1;
- GlobalFDSet.cap_let_recogn = SPD_CAP_NONE;
+ GlobalFDSet.msg_settings.voice_type = SPD_MALE1;
+ GlobalFDSet.msg_settings.cap_let_recogn = SPD_CAP_NONE;
GlobalFDSet.min_delay_progress = 2000;
GlobalFDSet.pause_context = 0;
GlobalFDSet.ssml_mode = SPD_DATA_TEXT;
diff --git a/src/server/output.c b/src/server/output.c
index 8c393d4..32e7564 100644
--- a/src/server/output.c
+++ b/src/server/output.c
@@ -389,7 +389,7 @@ output_list_voices(char* module_name)
g_string_append_printf(set_str, #name"=NULL\n"); \
}
#define ADD_SET_STR_C(name, fconv) \
- val = fconv(msg->settings.name); \
+ val = fconv(msg->settings.msg_settings.name); \
if (val != NULL){ \
g_string_append_printf(set_str, #name"=%s\n", val); \
}else{ \
@@ -406,15 +406,34 @@ output_send_settings(TSpeechDMessage *msg, OutputModule
*output)
MSG(4, "Module set parameters.");
set_str = g_string_new("");
- ADD_SET_INT(pitch);
- ADD_SET_INT(rate);
- ADD_SET_INT(volume);
+ g_string_append_printf(set_str, "pitch=%d\n",
+ msg->settings.msg_settings.pitch);
+ g_string_append_printf(set_str, "rate=%d\n",
+ msg->settings.msg_settings.rate);
+ g_string_append_printf(set_str, "volume=%d\n",
+ msg->settings.msg_settings.volume);
ADD_SET_STR_C(punctuation_mode, EPunctMode2str);
ADD_SET_STR_C(spelling_mode, ESpellMode2str);
ADD_SET_STR_C(cap_let_recogn, ECapLetRecogn2str);
- ADD_SET_STR(language);
- ADD_SET_STR_C(voice, EVoice2str);
- ADD_SET_STR(synthesis_voice)
+ val = EVoice2str(msg->settings.msg_settings.voice_type);
+ if (val != NULL){
+ g_string_append_printf(set_str, "voice=%s\n", val);
+ } else {
+ g_string_append_printf(set_str, "voice=NULL\n");
+ }
+ g_free(val);
+ if (msg->settings.msg_settings.voice.language != NULL) {
+ g_string_append_printf(set_str, "language=%s\n",
+ msg->settings.msg_settings.voice.language);
+ } else {
+ g_string_append_printf(set_str, "language=NULL\n");
+ }
+ if (msg->settings.msg_settings.voice.name != NULL) {
+ g_string_append_printf(set_str, "synthesis_voice=%s\n",
+ msg->settings.msg_settings.voice.name);
+ } else {
+ g_string_append_printf(set_str, "synthesis_voice=NULL\n");
+ }
SEND_CMD_N("SET");
SEND_DATA_N(set_str->str);
diff --git a/src/server/parse.c b/src/server/parse.c
index 0626e31..7431953 100644
--- a/src/server/parse.c
+++ b/src/server/parse.c
@@ -901,7 +901,7 @@ parse_get(const char *buf, const int bytes, const int fd,
const TSpeechDSock *sp
if(TEST_CMD(get_type, "voice")) {
result = g_string_new("");
- switch (settings->voice)
+ switch (settings->msg_settings.voice_type)
{
case SPD_MALE1:
g_string_append_printf(result, C_OK_GET"-MALE1\r\n");
diff --git a/src/server/server.c b/src/server/server.c
index 1f08224..3dab413 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -98,8 +98,8 @@ queue_message(TSpeechDMessage *new, int fd, int history_flag,
new->settings.index_mark = NULL;
COPY_SET_STR(client_name);
COPY_SET_STR(output_module);
- COPY_SET_STR(language);
- COPY_SET_STR(synthesis_voice);
+ COPY_SET_STR(msg_settings.voice.language);
+ COPY_SET_STR(msg_settings.voice.name);
COPY_SET_STR(index_mark);
COPY_SET_STR(audio_output_method);
diff --git a/src/server/set.c b/src/server/set.c
index ae511da..7739e02 100644
--- a/src/server/set.c
+++ b/src/server/set.c
@@ -100,7 +100,7 @@ set_rate_uid(int uid, int rate)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int(&settings->rate, rate);
+ set_param_int(&settings->msg_settings.rate, rate);
return 0;
}
@@ -117,7 +117,7 @@ set_pitch_uid(int uid, int pitch)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int(&settings->pitch, pitch);
+ set_param_int(&settings->msg_settings.pitch, pitch);
return 0;
}
@@ -133,7 +133,7 @@ set_volume_uid(int uid, int volume)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int(&settings->volume, volume);
+ set_param_int(&settings->msg_settings.volume, volume);
return 0;
}
@@ -147,19 +147,19 @@ set_voice_uid(int uid, char *voice)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- if (!strcmp(voice, "male1")) settings->voice = SPD_MALE1;
- else if (!strcmp(voice, "male2")) settings->voice = SPD_MALE2;
- else if (!strcmp(voice, "male3")) settings->voice = SPD_MALE3;
- else if (!strcmp(voice, "female1")) settings->voice = SPD_FEMALE1;
- else if (!strcmp(voice, "female2")) settings->voice = SPD_FEMALE2;
- else if (!strcmp(voice, "female3")) settings->voice = SPD_FEMALE3;
- else if (!strcmp(voice, "child_male")) settings->voice = SPD_CHILD_MALE;
- else if (!strcmp(voice, "child_female")) settings->voice =
SPD_CHILD_FEMALE;
+ if (!strcmp(voice, "male1")) settings->msg_settings.voice_type = SPD_MALE1;
+ else if (!strcmp(voice, "male2")) settings->msg_settings.voice_type =
SPD_MALE2;
+ else if (!strcmp(voice, "male3")) settings->msg_settings.voice_type =
SPD_MALE3;
+ else if (!strcmp(voice, "female1")) settings->msg_settings.voice_type =
SPD_FEMALE1;
+ else if (!strcmp(voice, "female2")) settings->msg_settings.voice_type =
SPD_FEMALE2;
+ else if (!strcmp(voice, "female3")) settings->msg_settings.voice_type =
SPD_FEMALE3;
+ else if (!strcmp(voice, "child_male")) settings->msg_settings.voice_type =
SPD_CHILD_MALE;
+ else if (!strcmp(voice, "child_female")) settings->msg_settings.voice_type
= SPD_CHILD_FEMALE;
else return 1;
- if (settings->synthesis_voice != NULL){
- g_free(settings->synthesis_voice);
- settings->synthesis_voice = NULL;
+ if (settings->msg_settings.voice.name != NULL){
+ g_free(settings->msg_settings.voice.name);
+ settings->msg_settings.voice.name = NULL;
}
return 0;
}
@@ -174,7 +174,7 @@ set_punctuation_mode_uid(int uid, SPDPunctuation
punctuation)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int((int*) &settings->punctuation_mode, punctuation);
+ set_param_int((int*) &settings->msg_settings.punctuation_mode,
punctuation);
return 0;
}
@@ -192,7 +192,7 @@ set_capital_letter_recognition_uid(int uid,
SPDCapitalLetters recogn)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int((int*) &settings->cap_let_recogn, (int) recogn);
+ set_param_int((int*) &settings->msg_settings.cap_let_recogn, (int) recogn);
return 0;
}
@@ -209,7 +209,7 @@ set_spelling_uid(int uid, SPDSpelling spelling)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- set_param_int((int*) &settings->spelling_mode, (int) spelling);
+ set_param_int((int*) &settings->msg_settings.spelling_mode, (int)
spelling);
return 0;
}
@@ -224,7 +224,8 @@ set_language_uid(int uid, char *language)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
- SET_PARAM_STR(language);
+ settings->msg_settings.voice.language =
+ set_param_str(settings->msg_settings.voice.language, language);
/* Check if it is not desired to change output module */
output_module = g_hash_table_lookup(language_default_modules, language);
@@ -243,11 +244,12 @@ set_synthesis_voice_uid(int uid, char *synthesis_voice)
settings = get_client_settings_by_uid(uid);
if (settings == NULL) return 1;
-
- SET_PARAM_STR(synthesis_voice);
+
+ settings->msg_settings.voice.name =
+ set_param_str(settings->msg_settings.voice.name, synthesis_voice);
/* Delete ordinary voice settings so that we don't mix */
- settings->voice = -1;
+ settings->msg_settings.voice_type = -1;
return 0;
}
@@ -274,16 +276,16 @@ update_cl_settings(gpointer data, gpointer user_data)
if (fnmatch(cl_set->pattern, set->client_name, 0)) return;
/* Warning: If you modify this, you must also modify cb_BeginClient in
config.c !*/
- CHECK_SET_PAR(rate, -101)
- CHECK_SET_PAR(pitch, -101)
- CHECK_SET_PAR(volume, -101)
- CHECK_SET_PAR(punctuation_mode, -1)
- CHECK_SET_PAR(spelling_mode, -1)
- CHECK_SET_PAR(voice, -1)
- CHECK_SET_PAR(cap_let_recogn, -1)
+ CHECK_SET_PAR(msg_settings.rate, -101)
+ CHECK_SET_PAR(msg_settings.pitch, -101)
+ CHECK_SET_PAR(msg_settings.volume, -101)
+ CHECK_SET_PAR(msg_settings.punctuation_mode, -1)
+ CHECK_SET_PAR(msg_settings.spelling_mode, -1)
+ CHECK_SET_PAR(msg_settings.voice_type, -1)
+ CHECK_SET_PAR(msg_settings.cap_let_recogn, -1)
CHECK_SET_PAR(pause_context, -1)
CHECK_SET_PAR(ssml_mode, -1)
- CHECK_SET_PAR_STR(language)
+ CHECK_SET_PAR_STR(msg_settings.voice.language)
CHECK_SET_PAR_STR(output_module)
@@ -335,9 +337,9 @@ set_output_module_uid(int uid, char* output_module)
SET_PARAM_STR(output_module);
/* Delete synth_voice since it is module specific */
- if (settings->synthesis_voice != NULL){
- g_free(settings->synthesis_voice);
- settings->synthesis_voice = NULL;
+ if (settings->msg_settings.voice.name != NULL){
+ g_free(settings->msg_settings.voice.name);
+ settings->msg_settings.voice.name = NULL;
}
return 0;
@@ -467,11 +469,11 @@ default_fd_set(void)
/* We can't use global_fdset copy as this
returns static structure and we need dynamic */
new->priority = GlobalFDSet.priority;
- new->punctuation_mode = GlobalFDSet.punctuation_mode;
- new->rate = GlobalFDSet.rate;
- new->pitch = GlobalFDSet.pitch;
- new->volume = GlobalFDSet.volume;
- new->language = g_strdup(GlobalFDSet.language);
+ new->msg_settings.punctuation_mode =
GlobalFDSet.msg_settings.punctuation_mode;
+ new->msg_settings.rate = GlobalFDSet.msg_settings.rate;
+ new->msg_settings.pitch = GlobalFDSet.msg_settings.pitch;
+ new->msg_settings.volume = GlobalFDSet.msg_settings.volume;
+ new->msg_settings.voice.language =
g_strdup(GlobalFDSet.msg_settings.voice.language);
new->output_module = g_strdup(GlobalFDSet.output_module);
new->client_name = g_strdup(GlobalFDSet.client_name);
new->index_mark = g_strdup(GlobalFDSet.index_mark);
@@ -481,10 +483,10 @@ default_fd_set(void)
new->audio_nas_server = g_strdup(GlobalFDSet.audio_nas_server);
new->audio_pulse_server = g_strdup(GlobalFDSet.audio_pulse_server);
- new->voice = GlobalFDSet.voice;
- new->synthesis_voice = NULL;
- new->spelling_mode = GlobalFDSet.spelling_mode;
- new->cap_let_recogn = GlobalFDSet.cap_let_recogn;
+ new->msg_settings.voice_type = GlobalFDSet.msg_settings.voice_type;
+ new->msg_settings.voice.name = NULL;
+ new->msg_settings.spelling_mode =
GlobalFDSet.msg_settings.spelling_mode;
+ new->msg_settings.cap_let_recogn =
GlobalFDSet.msg_settings.cap_let_recogn;
new->pause_context = GlobalFDSet.pause_context;
new->ssml_mode = GlobalFDSet.ssml_mode;
diff --git a/src/server/speechd.h b/src/server/speechd.h
index ebba274..078e701 100644
--- a/src/server/speechd.h
+++ b/src/server/speechd.h
@@ -81,20 +81,9 @@ typedef struct{
SPDMessageType type; /* Type of the message (1=text, 2=icon,
3=char, 4=key) */
SPDDataMode ssml_mode; /* SSML mode on (1)/off (0) */
SPDPriority priority; /* Priority between 1 and 5 (1 - highest, 5 -
lowest) */
- signed int rate; /* Speed of voice from <-100;+100>, 0 is the
default */
- signed int pitch; /* Pitch of voice from <-100;+100>, 0 is the
default */
- signed int volume; /* Volume of voice from <-100;+100), 0 is the
default */
- SPDPunctuation punctuation_mode; /* Punctuation mode: 0, 1 or 2
- 0 - no punctuation
- 1 - all punctuation
- 2 - only user-selected punctuation
*/
- SPDSpelling spelling_mode; /* Spelling mode: 0 or 1 (0 - off, 1 - on) */
+ SPDMsgSettings msg_settings;
char *client_name; /* Name of the client. */
- char *language; /* Selected language name. (e.g. "en", "cz",
"fr", ...) */
char *output_module; /* Output module name. (e.g. "festival",
"flite", "apollo", ...) */
- SPDVoiceType voice; /* see SPDVoiceType definition above */
- char *synthesis_voice;
- SPDCapitalLetters cap_let_recogn; /* Capital letters recognition:
(0 - off, 1 - on) */
SPDNotification notification; /* Notification about start and stop of
messages, about reached
index marks and state (canceled, paused,
resumed). */
--
1.6.0.4