Skip to content

Commit 87a0c47

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

File tree

11 files changed

+148
-27
lines changed

11 files changed

+148
-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: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#include "accessibility.h"
1920
#include <stdio.h>
2021
#include <stdint.h>
2122
#include <stddef.h>
@@ -2899,7 +2900,8 @@ static const char* accessibility_unix_language_code(const char* language)
28992900
string_is_equal(language, "ta") ||
29002901
string_is_equal(language, "te") ||
29012902
string_is_equal(language, "ur") ||
2902-
string_is_equal(language, "cy")
2903+
string_is_equal(language, "cy") ||
2904+
string_is_equal(language, "ca")
29032905
)
29042906
return language;
29052907
else if (
@@ -2908,19 +2910,16 @@ static const char* accessibility_unix_language_code(const char* language)
29082910
)
29092911
return "nb";
29102912
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";
2913+
return "en-GB";
2914+
else if (string_is_equal(language, "ca_ES@valencia"))
2915+
return "ca-VA";
29172916
else if (
29182917
string_is_equal(language, "pt_pt") ||
29192918
string_is_equal(language, "pt")
29202919
)
29212920
return "pt";
29222921
else if (string_is_equal(language, "pt_bt"))
2923-
return "pt-br";
2922+
return "pt-BR";
29242923
else if (
29252924
string_is_equal(language, "zh") ||
29262925
string_is_equal(language, "zh_cn") ||
@@ -2938,27 +2937,69 @@ static const char* accessibility_unix_language_code(const char* language)
29382937
static bool accessibility_speak_unix(int speed,
29392938
const char* speak_text, int priority)
29402939
{
2940+
unsigned synthesizer;
29412941
int pid;
29422942
const char* language = accessibility_unix_language_code(get_user_language_iso639_1(true));
29432943
char* voice_out = (char*)malloc(3 + strlen(language));
29442944
char* speed_out = (char*)malloc(3 + 3);
29452945
const char* speeds[10] = {"80", "100", "125", "150", "170", "210", "260", "310", "380", "450"};
2946+
char* executable = (char*)malloc(16);
2947+
2948+
settings_t *settings = config_get_ptr();
2949+
synthesizer = settings->uints.accessibility_narrator_synthesizer;
2950+
2951+
switch (synthesizer)
2952+
{
2953+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_SPEACH_DISPATCHER:
2954+
{
2955+
strlcpy(executable, "spd-say", 8);
2956+
speeds[0] = "-99";
2957+
speeds[1] = "-75";
2958+
speeds[2] = "-50";
2959+
speeds[3] = "-25";
2960+
speeds[4] = "0";
2961+
speeds[5] = "20";
2962+
speeds[6] = "40";
2963+
speeds[7] = "60";
2964+
speeds[8] = "80";
2965+
speeds[9] = "100";
2966+
2967+
voice_out[0] = '-';
2968+
voice_out[1] = 'l';
2969+
voice_out[2] = '\0';
2970+
strlcat(voice_out, language, sizeof(voice_out));
2971+
2972+
speed_out[0] = '-';
2973+
speed_out[1] = 'r';
2974+
speed_out[2] = '\0';
2975+
strlcat(speed_out, speeds[speed-1], sizeof(speed_out));
2976+
2977+
break;
2978+
}
2979+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_ESPEAK:
2980+
default:
2981+
{
2982+
strlcpy(executable, "espeak", 7);
2983+
2984+
voice_out[0] = '-';
2985+
voice_out[1] = 'v';
2986+
voice_out[2] = '\0';
2987+
strlcat(voice_out, language, sizeof(voice_out));
2988+
2989+
speed_out[0] = '-';
2990+
speed_out[1] = 's';
2991+
speed_out[2] = '\0';
2992+
strlcat(speed_out, speeds[speed-1], sizeof(speed_out));
2993+
2994+
break;
2995+
}
2996+
}
29462997

29472998
if (speed < 1)
29482999
speed = 1;
29493000
else if (speed > 10)
29503001
speed = 10;
29513002

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-
29623003
if (priority < 10 && speak_pid > 0)
29633004
{
29643005
/* check if old pid is running */
@@ -2968,7 +3009,7 @@ static bool accessibility_speak_unix(int speed,
29683009

29693010
if (speak_pid > 0)
29703011
{
2971-
/* Kill the running espeak */
3012+
/* Kill the running TTS Engine */
29723013
kill(speak_pid, SIGTERM);
29733014
speak_pid = 0;
29743015
}
@@ -2978,19 +3019,20 @@ static bool accessibility_speak_unix(int speed,
29783019
{
29793020
case 0:
29803021
{
2981-
/* child process: replace process with the espeak command */
2982-
char* cmd[] = { (char*) "espeak", NULL, NULL, NULL, NULL };
3022+
/* child process: replace process with the TTS command */
3023+
char* cmd[] = { NULL, NULL, NULL, NULL, NULL };
3024+
cmd[0] = executable;
29833025
cmd[1] = voice_out;
29843026
cmd[2] = speed_out;
29853027
cmd[3] = (char*)speak_text;
2986-
execvp("espeak", cmd);
3028+
execvp(executable, cmd);
29873029

2988-
RARCH_WARN("Could not execute espeak.\n");
3030+
RARCH_WARN("Could not execute TTS Engine.\n");
29893031
/* Prevent interfere with the parent process */
29903032
_exit(EXIT_FAILURE);
29913033
}
29923034
case -1:
2993-
RARCH_ERR("Could not fork for espeak.\n");
3035+
RARCH_ERR("Could not fork for the TTS process.\n");
29943036
default:
29953037
{
29963038
/* parent process */
@@ -3007,6 +3049,8 @@ static bool accessibility_speak_unix(int speed,
30073049
free(voice_out);
30083050
if (speed_out)
30093051
free(speed_out);
3052+
if (executable)
3053+
free(executable);
30103054
return true;
30113055
}
30123056
#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: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
#include <compat/strl.h>
3333

34+
#ifdef HAVE_ACCESSIBILITY
35+
#include "accessibility.h"
36+
#endif
37+
3438
#ifdef HAVE_CONFIG_H
3539
#include "../config.h"
3640
#endif
@@ -3175,6 +3179,27 @@ static size_t setting_get_string_representation_uint_keyboard_gamepad_mapping_ty
31753179
}
31763180
#endif
31773181

3182+
#ifdef HAVE_ACCESSIBILITY
3183+
static size_t setting_get_string_representation_uint_accessibility_narrator_synthesizer(
3184+
rarch_setting_t *setting, char *s, size_t len)
3185+
{
3186+
if (!setting)
3187+
return 0;
3188+
switch(*setting->value.target.unsigned_integer)
3189+
{
3190+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_NATIVE:
3191+
return strlcpy(s, "native", len);
3192+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_SPEACH_DISPATCHER:
3193+
return strlcpy(s, "Speech Dispatcher", len);
3194+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_ESPEAK:
3195+
return strlcpy(s, "eSpeak", len);
3196+
case ACCESSIBILITY_NARRATOR_SYNTHESIZER_LAST:
3197+
return 0;
3198+
}
3199+
return 0;
3200+
}
3201+
#endif
3202+
31783203
#ifdef HAVE_TRANSLATE
31793204
static size_t setting_get_string_representation_uint_ai_service_mode(
31803205
rarch_setting_t *setting, char *s, size_t len)
@@ -12110,7 +12135,7 @@ static bool setting_append_list(
1211012135
parent_group,
1211112136
general_write_handler,
1211212137
general_read_handler);
12113-
menu_settings_list_current_add_range(list, list_info,
12138+
menu_settings_list_current_add_range(list, list_info,
1211412139
0, cheat_manager_get_state_search_size(cheat_manager_state.working_cheat.memory_search_size), 1, true, true);
1211512140
(*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_hex_and_uint;
1211612141
SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ALLOW_INPUT);
@@ -12203,7 +12228,7 @@ static bool setting_append_list(
1220312228
parent_group,
1220412229
general_write_handler,
1220512230
general_read_handler);
12206-
menu_settings_list_current_add_range(list, list_info,
12231+
menu_settings_list_current_add_range(list, list_info,
1220712232
0, cheat_manager_get_state_search_size(cheat_manager_state.working_cheat.memory_search_size), 1, true, true);
1220812233
(*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_hex_and_uint;
1220912234
SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ALLOW_INPUT);
@@ -20553,6 +20578,24 @@ static bool setting_append_list(
2055320578
(*list)[list_info->index - 1].action_left = setting_bool_action_left_with_refresh;
2055420579
(*list)[list_info->index - 1].action_right = setting_bool_action_right_with_refresh;
2055520580

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

0 commit comments

Comments
 (0)