Skip to content

Commit d30e8cf

Browse files
committed
Change espeak to speech-dispatcher
1 parent 46fd8f6 commit d30e8cf

File tree

11 files changed

+153
-27
lines changed

11 files changed

+153
-27
lines changed

accessibility.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232

3333
#include "configuration.h"
3434

35+
36+
enum accessibility_narrator_synthesizer
37+
{
38+
ACCESSIBILITY_NARRATOR_SYNTHESIZER_NATIVE = 0,
39+
ACCESSIBILITY_NARRATOR_SYNTHESIZER_SPEACH_DISPATCHER,
40+
ACCESSIBILITY_NARRATOR_SYNTHESIZER_ESPEAK,
41+
ACCESSIBILITY_NARRATOR_SYNTHESIZER_LAST
42+
};
43+
3544
typedef struct
3645
{
3746
int ai_service_auto;

config.def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180

181181
#define DEFAULT_ACCESSIBILITY_ENABLE false
182182

183+
#define DEFAULT_ACCESSIBILITY_NARRATOR_SYNTHESIZER 0
184+
183185
#define DEFAULT_ACCESSIBILITY_NARRATOR_SPEECH_SPEED 5
184186

185187
#define DEFAULT_DRIVER_SWITCH_ENABLE true

configuration.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,7 @@ static struct config_uint_setting *populate_settings_uint(
26212621
SETTING_UINT("cheevos_appearance_anchor", &settings->uints.cheevos_appearance_anchor, true, DEFAULT_CHEEVOS_APPEARANCE_ANCHOR, false);
26222622
SETTING_UINT("cheevos_visibility_summary", &settings->uints.cheevos_visibility_summary, true, DEFAULT_CHEEVOS_VISIBILITY_SUMMARY, false);
26232623
#endif
2624+
SETTING_UINT("accessibility_narrator_synthesizer", &settings->uints.accessibility_narrator_synthesizer, true, DEFAULT_ACCESSIBILITY_NARRATOR_SYNTHESIZER, false);
26242625
SETTING_UINT("accessibility_narrator_speech_speed", &settings->uints.accessibility_narrator_speech_speed, true, DEFAULT_ACCESSIBILITY_NARRATOR_SPEECH_SPEED, false);
26252626
SETTING_UINT("ai_service_mode", &settings->uints.ai_service_mode, true, DEFAULT_AI_SERVICE_MODE, false);
26262627
SETTING_UINT("ai_service_target_lang", &settings->uints.ai_service_target_lang, true, 0, false);

configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ typedef struct settings
279279
#endif
280280

281281
/* Accessibility */
282+
unsigned accessibility_narrator_synthesizer;
282283
unsigned accessibility_narrator_speech_speed;
283284

284285
unsigned menu_timedate_style;

frontend/drivers/platform_unix.c

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#include <signal.h>
5252
#include <pthread.h>
5353

54+
#if (defined(__linux__) || defined(__HAIKU__) || defined(__unix__)) && !defined(ANDROID)
55+
#include "accessibility.h"
56+
#endif
57+
5458
#ifdef HAVE_CONFIG_H
5559
#include "../../config.h"
5660
#endif
@@ -2899,7 +2903,8 @@ static const char* accessibility_unix_language_code(const char* language)
28992903
string_is_equal(language, "ta") ||
29002904
string_is_equal(language, "te") ||
29012905
string_is_equal(language, "ur") ||
2902-
string_is_equal(language, "cy")
2906+
string_is_equal(language, "cy") ||
2907+
string_is_equal(language, "ca")
29032908
)
29042909
return language;
29052910
else if (
@@ -2908,19 +2913,16 @@ static const char* accessibility_unix_language_code(const char* language)
29082913
)
29092914
return "nb";
29102915
else if (string_is_equal(language, "en_gb"))
2911-
return "en-gb";
2912-
else if (
2913-
string_is_equal(language, "ca") ||
2914-
string_is_equal(language, "ca_ES@valencia")
2915-
)
2916-
return "ca";
2916+
return "en-GB";
2917+
else if (string_is_equal(language, "ca_ES@valencia"))
2918+
return "ca-VA";
29172919
else if (
29182920
string_is_equal(language, "pt_pt") ||
29192921
string_is_equal(language, "pt")
29202922
)
29212923
return "pt";
29222924
else if (string_is_equal(language, "pt_bt"))
2923-
return "pt-br";
2925+
return "pt-BR";
29242926
else if (
29252927
string_is_equal(language, "zh") ||
29262928
string_is_equal(language, "zh_cn") ||
@@ -2938,27 +2940,69 @@ static const char* accessibility_unix_language_code(const char* language)
29382940
static bool accessibility_speak_unix(int speed,
29392941
const char* speak_text, int priority)
29402942
{
2943+
unsigned synthesizer;
29412944
int pid;
29422945
const char* language = accessibility_unix_language_code(get_user_language_iso639_1(true));
29432946
char* voice_out = (char*)malloc(3 + strlen(language));
29442947
char* speed_out = (char*)malloc(3 + 3);
29452948
const char* speeds[10] = {"80", "100", "125", "150", "170", "210", "260", "310", "380", "450"};
2949+
char* executable = (char*)malloc(16);
2950+
2951+
settings_t *settings = config_get_ptr();
2952+
synthesizer = settings->uints.accessibility_narrator_synthesizer;
2953+
2954+
switch (synthesizer)
2955+
{
2956+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_SPEACH_DISPATCHER:
2957+
{
2958+
strlcpy(executable, "spd-say", 8);
2959+
speeds[0] = "-99";
2960+
speeds[1] = "-75";
2961+
speeds[2] = "-50";
2962+
speeds[3] = "-25";
2963+
speeds[4] = "0";
2964+
speeds[5] = "20";
2965+
speeds[6] = "40";
2966+
speeds[7] = "60";
2967+
speeds[8] = "80";
2968+
speeds[9] = "100";
2969+
2970+
voice_out[0] = '-';
2971+
voice_out[1] = 'l';
2972+
voice_out[2] = '\0';
2973+
strlcat(voice_out, language, sizeof(voice_out));
2974+
2975+
speed_out[0] = '-';
2976+
speed_out[1] = 'r';
2977+
speed_out[2] = '\0';
2978+
strlcat(speed_out, speeds[speed-1], sizeof(speed_out));
2979+
2980+
break;
2981+
}
2982+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_ESPEAK:
2983+
default:
2984+
{
2985+
strlcpy(executable, "espeak", 7);
2986+
2987+
voice_out[0] = '-';
2988+
voice_out[1] = 'v';
2989+
voice_out[2] = '\0';
2990+
strlcat(voice_out, language, sizeof(voice_out));
2991+
2992+
speed_out[0] = '-';
2993+
speed_out[1] = 's';
2994+
speed_out[2] = '\0';
2995+
strlcat(speed_out, speeds[speed-1], sizeof(speed_out));
2996+
2997+
break;
2998+
}
2999+
}
29463000

29473001
if (speed < 1)
29483002
speed = 1;
29493003
else if (speed > 10)
29503004
speed = 10;
29513005

2952-
voice_out[0] = '-';
2953-
voice_out[1] = 'v';
2954-
voice_out[2] = '\0';
2955-
strlcat(voice_out, language, 3 + strlen(language));
2956-
2957-
speed_out[0] = '-';
2958-
speed_out[1] = 's';
2959-
speed_out[2] = '\0';
2960-
strlcat(speed_out, speeds[speed-1], 6);
2961-
29623006
if (priority < 10 && speak_pid > 0)
29633007
{
29643008
/* check if old pid is running */
@@ -2968,7 +3012,7 @@ static bool accessibility_speak_unix(int speed,
29683012

29693013
if (speak_pid > 0)
29703014
{
2971-
/* Kill the running espeak */
3015+
/* Kill the running TTS Engine */
29723016
kill(speak_pid, SIGTERM);
29733017
speak_pid = 0;
29743018
}
@@ -2978,19 +3022,20 @@ static bool accessibility_speak_unix(int speed,
29783022
{
29793023
case 0:
29803024
{
2981-
/* child process: replace process with the espeak command */
2982-
char* cmd[] = { (char*) "espeak", NULL, NULL, NULL, NULL };
3025+
/* child process: replace process with the TTS command */
3026+
char* cmd[] = { NULL, NULL, NULL, NULL, NULL };
3027+
cmd[0] = executable;
29833028
cmd[1] = voice_out;
29843029
cmd[2] = speed_out;
29853030
cmd[3] = (char*)speak_text;
2986-
execvp("espeak", cmd);
3031+
execvp(executable, cmd);
29873032

2988-
RARCH_WARN("Could not execute espeak.\n");
3033+
RARCH_WARN("Could not execute TTS Engine.\n");
29893034
/* Prevent interfere with the parent process */
29903035
_exit(EXIT_FAILURE);
29913036
}
29923037
case -1:
2993-
RARCH_ERR("Could not fork for espeak.\n");
3038+
RARCH_ERR("Could not fork for the TTS process.\n");
29943039
default:
29953040
{
29963041
/* parent process */
@@ -3007,6 +3052,8 @@ static bool accessibility_speak_unix(int speed,
30073052
free(voice_out);
30083053
if (speed_out)
30093054
free(speed_out);
3055+
if (executable)
3056+
free(executable);
30103057
return true;
30113058
}
30123059
#endif

intl/msg_hash_lbl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ MSG_HASH(
21752175
MSG_HASH(
21762176
MENU_ENUM_LABEL_INPUT_REMAP_SORT_BY_CONTROLLER_ENABLE,
21772177
"input_remap_sort_by_controller_enable"
2178-
)
2178+
)
21792179
MSG_HASH(
21802180
MENU_ENUM_LABEL_INPUT_SETTINGS,
21812181
"input_settings"
@@ -6580,6 +6580,10 @@ MSG_HASH(
65806580
MENU_ENUM_LABEL_ACCESSIBILITY_ENABLED,
65816581
"accessibility_enabled"
65826582
)
6583+
MSG_HASH(
6584+
MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
6585+
"accessibility_narrator_synthesizer"
6586+
)
65836587
MSG_HASH(
65846588
MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SPEECH_SPEED,
65856589
"accessibility_narrator_speech_speed"

intl/msg_hash_us.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7235,6 +7235,14 @@ MSG_HASH(
72357235
MENU_ENUM_SUBLABEL_ACCESSIBILITY_ENABLED,
72367236
"Enable Text-to-Speech to aid in menu navigation."
72377237
)
7238+
MSG_HASH(
7239+
MENU_ENUM_LABEL_VALUE_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
7240+
"Text-to-Speech synthesizer"
7241+
)
7242+
MSG_HASH(
7243+
MENU_ENUM_SUBLABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
7244+
"The engine of the Text-to-Speech synthesis."
7245+
)
72387246
MSG_HASH(
72397247
MENU_ENUM_LABEL_VALUE_ACCESSIBILITY_NARRATOR_SPEECH_SPEED,
72407248
"Text-to-Speech Speed"

menu/cbs/menu_cbs_sublabel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ DEFAULT_SUBLABEL_MACRO(menu_action_sublabel_setting_audio_mixer_stream_volume,
231231
MENU_ENUM_SUBLABEL_MIXER_ACTION_VOLUME)
232232
#endif
233233
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_accessibility_enabled, MENU_ENUM_SUBLABEL_ACCESSIBILITY_ENABLED)
234+
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_accessibility_narrator_synthesizer, MENU_ENUM_SUBLABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER)
234235
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_accessibility_narrator_speech_speed, MENU_ENUM_SUBLABEL_ACCESSIBILITY_NARRATOR_SPEECH_SPEED)
235236

236237
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_load_config, MENU_ENUM_SUBLABEL_CONFIGURATIONS)
@@ -5342,6 +5343,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
53425343
case MENU_ENUM_LABEL_ACCESSIBILITY_ENABLED:
53435344
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_accessibility_enabled);
53445345
break;
5346+
case MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER:
5347+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_accessibility_narrator_synthesizer);
5348+
break;
53455349
case MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SPEECH_SPEED:
53465350
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_accessibility_narrator_speech_speed);
53475351
break;

menu/menu_displaylist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8296,6 +8296,7 @@ unsigned menu_displaylist_build_list(
82968296
bool accessibility_enable = settings->bools.accessibility_enable;
82978297
menu_displaylist_build_info_selective_t build_list[] = {
82988298
{MENU_ENUM_LABEL_ACCESSIBILITY_ENABLED, PARSE_ONLY_BOOL, true },
8299+
{MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER, PARSE_ONLY_UINT, false },
82998300
{MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SPEECH_SPEED, PARSE_ONLY_UINT, false },
83008301
{MENU_ENUM_LABEL_AI_SERVICE_SETTINGS, PARSE_ACTION, true },
83018302
};
@@ -8304,6 +8305,9 @@ unsigned menu_displaylist_build_list(
83048305
{
83058306
switch (build_list[i].enum_idx)
83068307
{
8308+
#if (defined(__linux__) || defined(__unix__)) && !defined(ANDROID)
8309+
case MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER:
8310+
#endif
83078311
case MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SPEECH_SPEED:
83088312
if (accessibility_enable)
83098313
build_list[i].checked = true;

menu/menu_setting.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
#include <compat/strl.h>
3333

34+
#ifdef HAVE_ACCESSIBILITY
35+
#if (defined(__linux__) || defined(__HAIKU__) || defined(__unix__)) && !defined(ANDROID)
36+
#include "accessibility.h"
37+
#endif
38+
#endif
39+
3440
#ifdef HAVE_CONFIG_H
3541
#include "../config.h"
3642
#endif
@@ -3175,6 +3181,27 @@ static size_t setting_get_string_representation_uint_keyboard_gamepad_mapping_ty
31753181
}
31763182
#endif
31773183

3184+
#ifdef HAVE_ACCESSIBILITY
3185+
static size_t setting_get_string_representation_uint_accessibility_narrator_synthesizer(
3186+
rarch_setting_t *setting, char *s, size_t len)
3187+
{
3188+
if (!setting)
3189+
return 0;
3190+
switch(*setting->value.target.unsigned_integer)
3191+
{
3192+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_NATIVE:
3193+
return strlcpy(s, "native", len);
3194+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_SPEACH_DISPATCHER:
3195+
return strlcpy(s, "Speech Dispatcher", len);
3196+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_ESPEAK:
3197+
return strlcpy(s, "eSpeak", len);
3198+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_LAST:
3199+
return 0;
3200+
}
3201+
return 0;
3202+
}
3203+
#endif
3204+
31783205
#ifdef HAVE_TRANSLATE
31793206
static size_t setting_get_string_representation_uint_ai_service_mode(
31803207
rarch_setting_t *setting, char *s, size_t len)
@@ -12110,7 +12137,7 @@ static bool setting_append_list(
1211012137
parent_group,
1211112138
general_write_handler,
1211212139
general_read_handler);
12113-
menu_settings_list_current_add_range(list, list_info,
12140+
menu_settings_list_current_add_range(list, list_info,
1211412141
0, cheat_manager_get_state_search_size(cheat_manager_state.working_cheat.memory_search_size), 1, true, true);
1211512142
(*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_hex_and_uint;
1211612143
SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ALLOW_INPUT);
@@ -12203,7 +12230,7 @@ static bool setting_append_list(
1220312230
parent_group,
1220412231
general_write_handler,
1220512232
general_read_handler);
12206-
menu_settings_list_current_add_range(list, list_info,
12233+
menu_settings_list_current_add_range(list, list_info,
1220712234
0, cheat_manager_get_state_search_size(cheat_manager_state.working_cheat.memory_search_size), 1, true, true);
1220812235
(*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_hex_and_uint;
1220912236
SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ALLOW_INPUT);
@@ -20553,6 +20580,24 @@ static bool setting_append_list(
2055320580
(*list)[list_info->index - 1].action_left = setting_bool_action_left_with_refresh;
2055420581
(*list)[list_info->index - 1].action_right = setting_bool_action_right_with_refresh;
2055520582

20583+
#ifdef HAVE_ACCESSIBILITY
20584+
CONFIG_UINT(
20585+
list, list_info,
20586+
&settings->uints.accessibility_narrator_synthesizer,
20587+
MENU_ENUM_LABEL_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
20588+
MENU_ENUM_LABEL_VALUE_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
20589+
DEFAULT_ACCESSIBILITY_NARRATOR_SYNTHESIZER,
20590+
&group_info,
20591+
&subgroup_info,
20592+
parent_group,
20593+
general_write_handler,
20594+
general_read_handler);
20595+
(*list)[list_info->index - 1].get_string_representation =
20596+
&setting_get_string_representation_uint_accessibility_narrator_synthesizer;
20597+
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint;
20598+
menu_settings_list_current_add_range(list, list_info, ACCESSIBILITY_NARRATOR_SYNTHESIZER_NATIVE, (ACCESSIBILITY_NARRATOR_SYNTHESIZER_LAST - 1), 1, true, true);
20599+
#endif
20600+
2055620601
CONFIG_UINT(
2055720602
list, list_info,
2055820603
&settings->uints.accessibility_narrator_speech_speed,

0 commit comments

Comments
 (0)