Fix narrator modes (#16179)

* Fix narrator

* Refactor accessibility
This commit is contained in:
Viačasłaŭ Chalikin 2024-02-09 05:14:23 +00:00 committed by GitHub
parent 156dd055d9
commit 997c7453a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 358 additions and 359 deletions

View File

@ -138,10 +138,19 @@ bool run_translation_service(settings_t *settings, bool paused);
void translation_release(bool inform); void translation_release(bool inform);
bool accessibility_speak_priority( /* Proxy for calls related to menu navigation */
bool navigation_say(
bool accessibility_enable, bool accessibility_enable,
unsigned accessibility_narrator_speech_speed, unsigned accessibility_narrator_speech_speed,
const char* speak_text, int priority); const char* speak_text,
int priority);
/* Local platform-specific TTS */
bool accessibility_speak_priority(
unsigned accessibility_narrator_speech_speed,
const char *speak_text,
int priority,
const char* voice);
access_state_t *access_state_get_ptr(void); access_state_t *access_state_get_ptr(void);

View File

@ -885,10 +885,9 @@ static bool is_narrator_running_macos(void)
} }
static bool accessibility_speak_macos(int speed, static bool accessibility_speak_macos(int speed,
const char* speak_text, int priority) const char* speak_text, int priority, const char* voice)
{ {
int pid; int pid;
const char *voice = get_user_language_iso639_1(false);
char* language_speaker = accessibility_mac_language_code(voice); char* language_speaker = accessibility_mac_language_code(voice);
char* speeds[10] = {"80", "100", "125", "150", "170", "210", char* speeds[10] = {"80", "100", "125", "150", "170", "210",
"260", "310", "380", "450"}; "260", "310", "380", "450"};

View File

@ -82,7 +82,6 @@
#include "../../msg_hash.h" #include "../../msg_hash.h"
#include "../../paths.h" #include "../../paths.h"
#include "../../retroarch.h" #include "../../retroarch.h"
#include "../../translation_defines.h"
#include "../../verbosity.h" #include "../../verbosity.h"
#ifdef HAVE_MENU #ifdef HAVE_MENU
@ -2789,152 +2788,106 @@ static bool is_narrator_running_unix(void)
return (kill(speak_pid, 0) == 0); return (kill(speak_pid, 0) == 0);
} }
/** static const char* accessibility_unix_language_code(const char* language)
* Returns the espeak-compatible string representation of the translation language enum value.
*/
static const char* espeak_get_str(enum translation_lang id)
{ {
switch (id) if (
{ string_is_equal(language, "en") ||
case TRANSLATION_LANG_EN: string_is_equal(language, "it") ||
return "en"; string_is_equal(language, "sv") ||
case TRANSLATION_LANG_ES: string_is_equal(language, "fr") ||
return "es"; string_is_equal(language, "de") ||
case TRANSLATION_LANG_FR: string_is_equal(language, "he") ||
return "fr"; string_is_equal(language, "id") ||
case TRANSLATION_LANG_IT: string_is_equal(language, "es") ||
return "it"; string_is_equal(language, "nl") ||
case TRANSLATION_LANG_DE: string_is_equal(language, "ro") ||
return "de"; string_is_equal(language, "th") ||
case TRANSLATION_LANG_JP: string_is_equal(language, "ja") ||
return "ja"; string_is_equal(language, "sk") ||
case TRANSLATION_LANG_NL: string_is_equal(language, "hi") ||
return "nl"; string_is_equal(language, "ar") ||
case TRANSLATION_LANG_CS: string_is_equal(language, "hu") ||
return "cs"; string_is_equal(language, "el") ||
case TRANSLATION_LANG_DA: string_is_equal(language, "ru") ||
return "da"; string_is_equal(language, "nb") ||
case TRANSLATION_LANG_SV: string_is_equal(language, "da") ||
return "sv"; string_is_equal(language, "fi") ||
case TRANSLATION_LANG_HR: string_is_equal(language, "tr") ||
return "hr"; string_is_equal(language, "ko") ||
case TRANSLATION_LANG_KO: string_is_equal(language, "pl") ||
return "ko"; string_is_equal(language, "cs") ||
case TRANSLATION_LANG_ZH_CN: string_is_equal(language, "eo") ||
case TRANSLATION_LANG_ZH_TW: string_is_equal(language, "vi") ||
return "cmn"; string_is_equal(language, "fa") ||
case TRANSLATION_LANG_CA: string_is_equal(language, "uk") ||
return "ca"; string_is_equal(language, "be") ||
case TRANSLATION_LANG_BG: string_is_equal(language, "hr") ||
return "bg"; string_is_equal(language, "bg") ||
case TRANSLATION_LANG_BN: string_is_equal(language, "bn") ||
return "bn"; string_is_equal(language, "eu") ||
case TRANSLATION_LANG_EU: string_is_equal(language, "az") ||
return "eu"; string_is_equal(language, "sq") ||
case TRANSLATION_LANG_AZ: string_is_equal(language, "af") ||
return "az"; string_is_equal(language, "et") ||
case TRANSLATION_LANG_AR: string_is_equal(language, "ka") ||
return "ar"; string_is_equal(language, "gu") ||
case TRANSLATION_LANG_SQ: string_is_equal(language, "ht") ||
return "sq"; string_is_equal(language, "is") ||
case TRANSLATION_LANG_AF: string_is_equal(language, "ga") ||
return "af"; string_is_equal(language, "kn") ||
case TRANSLATION_LANG_EO: string_is_equal(language, "la") ||
return "eo"; string_is_equal(language, "lv") ||
case TRANSLATION_LANG_ET: string_is_equal(language, "lt") ||
return "et"; string_is_equal(language, "mk") ||
case TRANSLATION_LANG_FI: string_is_equal(language, "ms") ||
return "fi"; string_is_equal(language, "mt") ||
case TRANSLATION_LANG_KA: string_is_equal(language, "sr") ||
return "ka"; string_is_equal(language, "sl") ||
case TRANSLATION_LANG_EL: string_is_equal(language, "sw") ||
return "el"; string_is_equal(language, "ta") ||
case TRANSLATION_LANG_GU: string_is_equal(language, "te") ||
return "gu"; string_is_equal(language, "ur") ||
case TRANSLATION_LANG_HT: string_is_equal(language, "cy")
return "ht"; )
case TRANSLATION_LANG_HE: return language;
return "he"; else if (
case TRANSLATION_LANG_HI: string_is_equal(language, "no") ||
return "hi"; string_is_equal(language, "nb")
case TRANSLATION_LANG_HU: )
return "hu";
case TRANSLATION_LANG_IS:
return "is";
case TRANSLATION_LANG_ID:
return "id";
case TRANSLATION_LANG_GA:
return "ga";
case TRANSLATION_LANG_KN:
return "kn";
case TRANSLATION_LANG_LA:
return "la";
case TRANSLATION_LANG_LV:
return "lv";
case TRANSLATION_LANG_LT:
return "lt";
case TRANSLATION_LANG_MK:
return "mk";
case TRANSLATION_LANG_MS:
return "ms";
case TRANSLATION_LANG_MT:
return "mt";
case TRANSLATION_LANG_NO:
return "nb"; return "nb";
case TRANSLATION_LANG_FA: else if (string_is_equal(language, "en_gb"))
return "fa"; return "en-gb";
case TRANSLATION_LANG_PL: else if (
return "pl"; string_is_equal(language, "ca") ||
case TRANSLATION_LANG_PT: string_is_equal(language, "ca_ES@valencia")
)
return "ca";
else if (
string_is_equal(language, "pt_pt") ||
string_is_equal(language, "pt")
)
return "pt"; return "pt";
case TRANSLATION_LANG_RO: else if (string_is_equal(language, "pt_bt"))
return "ro"; return "pt-br";
case TRANSLATION_LANG_RU: else if (
return "ru"; string_is_equal(language, "zh") ||
case TRANSLATION_LANG_SR: string_is_equal(language, "zh_cn") ||
return "sr"; string_is_equal(language, "zh_tw") ||
case TRANSLATION_LANG_SK: string_is_equal(language, "zh-CN") ||
return "sk"; string_is_equal(language, "zh-TW")
case TRANSLATION_LANG_SL: )
return "sl"; return "cmn";
case TRANSLATION_LANG_SW: else if (string_is_equal(language, "zh_hk"))
return "sw"; return "yue";
case TRANSLATION_LANG_TA: /* default voice as fallback */
return "ta";
case TRANSLATION_LANG_TE:
return "te";
case TRANSLATION_LANG_TH:
return "th";
case TRANSLATION_LANG_TR:
return "tr";
case TRANSLATION_LANG_UK:
return "uk";
case TRANSLATION_LANG_BE:
return "be";
case TRANSLATION_LANG_UR:
return "ur";
case TRANSLATION_LANG_VI:
return "vi";
case TRANSLATION_LANG_CY:
return "cy";
case TRANSLATION_LANG_AST:
case TRANSLATION_LANG_TL:
case TRANSLATION_LANG_GL:
case TRANSLATION_LANG_YI:
case TRANSLATION_LANG_DONT_CARE:
case TRANSLATION_LANG_LAST:
break;
}
return "en"; return "en";
} }
static bool accessibility_speak_unix(int speed, static bool accessibility_speak_unix(int speed,
const char* speak_text, int priority) const char* speak_text, int priority, const char* voice)
{ {
int pid; int pid;
settings_t *settings = config_get_ptr(); const char* language = accessibility_unix_language_code(voice);
unsigned target_lang = settings->uints.ai_service_target_lang;
const char *language = espeak_get_str((enum translation_lang)target_lang);
char* voice_out = (char*)malloc(3 + strlen(language)); char* voice_out = (char*)malloc(3 + strlen(language));
char* speed_out = (char*)malloc(3 + 3); char* speed_out = (char*)malloc(3 + 3);
const char* speeds[10] = {"80", "100", "125", "150", "170", "210", "260", "310", "380", "450"}; const char* speeds[10] = {"80", "100", "125", "150", "170", "210", "260", "310", "380", "450"};

View File

@ -831,7 +831,7 @@ static const char *accessibility_win_language_id(const char* language)
return "401"; return "401";
else if (string_is_equal(language,"hu")) else if (string_is_equal(language,"hu"))
return "040e"; return "040e";
else if (string_is_equal(language,"zh_tw") || string_is_equal(language,"zh")) else if (string_is_equal(language, "zh_tw") || string_is_equal(language,"zh"))
return "804"; return "804";
else if (string_is_equal(language,"el")) else if (string_is_equal(language,"el"))
return "408"; return "408";
@ -896,13 +896,15 @@ static const char *accessibility_win_language_code(const char* language)
return "Microsoft Naayf Desktop"; return "Microsoft Naayf Desktop";
else if (string_is_equal(language,"hu")) else if (string_is_equal(language,"hu"))
return "Microsoft Szabolcs Desktop"; return "Microsoft Szabolcs Desktop";
else if (string_is_equal(language,"zh_tw") || string_is_equal(language,"zh")) else if (string_is_equal(language, "zh_tw")
|| string_is_equal(language,"zh-TW")
|| string_is_equal(language,"zh"))
return "Microsoft Zhiwei Desktop"; return "Microsoft Zhiwei Desktop";
else if (string_is_equal(language,"el")) else if (string_is_equal(language,"el"))
return "Microsoft Stefanos Desktop"; return "Microsoft Stefanos Desktop";
else if (string_is_equal(language,"ru")) else if (string_is_equal(language,"ru"))
return "Microsoft Pavel Desktop"; return "Microsoft Pavel Desktop";
else if (string_is_equal(language,"nb")) else if (string_is_equal(language,"no") || string_is_equal(language,"nb"))
return "Microsoft Jon Desktop"; return "Microsoft Jon Desktop";
else if (string_is_equal(language,"da")) else if (string_is_equal(language,"da"))
return "Microsoft Helle Desktop"; return "Microsoft Helle Desktop";
@ -910,7 +912,7 @@ static const char *accessibility_win_language_code(const char* language)
return "Microsoft Heidi Desktop"; return "Microsoft Heidi Desktop";
else if (string_is_equal(language,"zh_hk")) else if (string_is_equal(language,"zh_hk"))
return "Microsoft Danny Desktop"; return "Microsoft Danny Desktop";
else if (string_is_equal(language,"zh_cn")) else if (string_is_equal(language,"zh_cn") || string_is_equal(language,"zh-CN"))
return "Microsoft Kangkang Desktop"; return "Microsoft Kangkang Desktop";
else if (string_is_equal(language,"tr")) else if (string_is_equal(language,"tr"))
return "Microsoft Tolga Desktop"; return "Microsoft Tolga Desktop";
@ -920,6 +922,22 @@ static const char *accessibility_win_language_code(const char* language)
return "Microsoft Adam Desktop"; return "Microsoft Adam Desktop";
else if (string_is_equal(language,"cs")) else if (string_is_equal(language,"cs"))
return "Microsoft Jakub Desktop"; return "Microsoft Jakub Desktop";
else if (string_is_equal(language,"vi"))
return "Microsoft An Desktop";
else if (string_is_equal(language,"hr"))
return "Microsoft Matej Desktop";
else if (string_is_equal(language,"bg"))
return "Microsoft Ivan Desktop";
else if (string_is_equal(language,"ms"))
return "Microsoft Rizwan Desktop";
else if (string_is_equal(language,"sl"))
return "Microsoft Lado Desktop";
else if (string_is_equal(language,"ta"))
return "Microsoft Valluvar Desktop";
else if (string_is_equal(language,"en_gb"))
return "Microsoft George Desktop";
else if (string_is_equal(language,"ca") || string_is_equal(language,"ca_ES@valencia"))
return "Microsoft Herena Desktop";
return ""; return "";
} }
@ -1017,10 +1035,9 @@ static bool is_narrator_running_windows(void)
} }
static bool accessibility_speak_windows(int speed, static bool accessibility_speak_windows(int speed,
const char* speak_text, int priority) const char* speak_text, int priority, const char* voice)
{ {
char cmd[512]; char cmd[512];
const char *voice = get_user_language_iso639_1(true);
const char *language = accessibility_win_language_code(voice); const char *language = accessibility_win_language_code(voice);
const char *langid = accessibility_win_language_id(voice); const char *langid = accessibility_win_language_id(voice);
bool res = false; bool res = false;
@ -1069,7 +1086,7 @@ static bool accessibility_speak_windows(int speed,
g_plat_win32_flags |= PLAT_WIN32_FLAG_USE_POWERSHELL; g_plat_win32_flags |= PLAT_WIN32_FLAG_USE_POWERSHELL;
if (wc) if (wc)
free(wc); free(wc);
return accessibility_speak_windows(speed, speak_text, priority); return accessibility_speak_windows(speed, speak_text, priority, voice);
} }
nvdaController_cancelSpeech_func(); nvdaController_cancelSpeech_func();

View File

@ -112,7 +112,7 @@ typedef struct frontend_ctx_driver
enum retro_language (*get_user_language)(void); enum retro_language (*get_user_language)(void);
bool (*is_narrator_running)(void); bool (*is_narrator_running)(void);
bool (*accessibility_speak)(int speed, bool (*accessibility_speak)(int speed,
const char* speak_text, int priority); const char* speak_text, int priority, const char* voice);
bool (*set_gamemode)(bool on); bool (*set_gamemode)(bool on);
const char *ident; const char *ident;

View File

@ -6614,7 +6614,7 @@ void input_keyboard_event(bool down, unsigned code,
say_char[1] = '\0'; say_char[1] = '\0';
if (character == 127 || character == 8) if (character == 127 || character == 8)
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
"backspace", 10); "backspace", 10);
@ -6622,12 +6622,12 @@ void input_keyboard_event(bool down, unsigned code,
{ {
const char *lut_name = accessibility_lut_name(c); const char *lut_name = accessibility_lut_name(c);
if (lut_name) if (lut_name)
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
lut_name, 10); lut_name, 10);
else if (character != 0) else if (character != 0)
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
say_char, 10); say_char, 10);

View File

@ -7016,7 +7016,7 @@ static int generic_menu_iterate(
&& is_accessibility_enabled( && is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
menu->menu_state_msg, 10); menu->menu_state_msg, 10);
@ -7148,18 +7148,18 @@ static int generic_menu_iterate(
menu_st, menu_st,
current_sublabel, sizeof(current_sublabel)); current_sublabel, sizeof(current_sublabel));
if (string_is_equal(current_sublabel, "")) if (string_is_equal(current_sublabel, ""))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
menu->menu_state_msg, 10); menu->menu_state_msg, 10);
else else
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
current_sublabel, 10); current_sublabel, 10);
} }
else else
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
menu->menu_state_msg, 10); menu->menu_state_msg, 10);
@ -7321,7 +7321,7 @@ static int generic_menu_iterate(
&& is_accessibility_enabled( && is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
"Closed dialog.", 10); "Closed dialog.", 10);
@ -7759,7 +7759,7 @@ int generic_menu_entry_action(
} }
if (!string_is_empty(speak_string)) if (!string_is_empty(speak_string))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
speak_string, 10); speak_string, 10);
@ -7892,7 +7892,7 @@ bool menu_input_dialog_start_search(void)
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SEARCH), 10); (char*)msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SEARCH), 10);
@ -7946,7 +7946,7 @@ bool menu_input_dialog_start(menu_input_ctx_line_t *line)
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
"Keyboard input:", 10); "Keyboard input:", 10);

View File

@ -3169,7 +3169,7 @@ bool command_event(enum event_command cmd, void *data)
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_UNPAUSED), 10); (char*)msg_hash_to_str(MSG_UNPAUSED), 10);
@ -4559,12 +4559,12 @@ bool command_event(enum event_command cmd, void *data)
access_st->enabled)) access_st->enabled))
{ {
if (paused) if (paused)
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_PAUSED), 10); (char*)msg_hash_to_str(MSG_PAUSED), 10);
else else
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_UNPAUSED), 10); (char*)msg_hash_to_str(MSG_UNPAUSED), 10);
@ -5312,7 +5312,7 @@ bool command_event(enum event_command cmd, void *data)
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_AI_SERVICE_STOPPED), (char*)msg_hash_to_str(MSG_AI_SERVICE_STOPPED),
@ -5327,7 +5327,7 @@ bool command_event(enum event_command cmd, void *data)
access_st->enabled) access_st->enabled)
&& (ai_service_mode == 2) && (ai_service_mode == 2)
&& is_narrator_running(accessibility_enable)) && is_narrator_running(accessibility_enable))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_AI_SERVICE_STOPPED), (char*)msg_hash_to_str(MSG_AI_SERVICE_STOPPED),
@ -7386,7 +7386,7 @@ bool retroarch_main_init(int argc, char *argv[])
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg_hash_to_str(MSG_ACCESSIBILITY_STARTUP), (char*)msg_hash_to_str(MSG_ACCESSIBILITY_STARTUP),
@ -8337,7 +8337,7 @@ void retroarch_favorites_deinit(void)
} }
#ifdef HAVE_ACCESSIBILITY #ifdef HAVE_ACCESSIBILITY
bool accessibility_speak_priority( bool navigation_say(
bool accessibility_enable, bool accessibility_enable,
unsigned accessibility_narrator_speech_speed, unsigned accessibility_narrator_speech_speed,
const char* speak_text, int priority) const char* speak_text, int priority)
@ -8347,29 +8347,48 @@ bool accessibility_speak_priority(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
{ {
frontend_ctx_driver_t *frontend = const char *voice = get_user_language_iso639_1(false);
frontend_state_get_ptr()->current_frontend_ctx; bool native_narrator = accessibility_speak_priority(accessibility_narrator_speech_speed,
speak_text, priority, voice);
RARCH_LOG("Spoke: %s\n", speak_text); if (!native_narrator)
{
if (frontend && frontend->accessibility_speak) /*
return frontend->accessibility_speak(accessibility_narrator_speech_speed, speak_text, * The following method is a fallback for other platforms to use the
priority); * AI Service url to do the TTS. However, since the playback is done
* via the audio mixer, which only processes the audio while the
RARCH_LOG("Platform not supported for accessibility.\n"); * core is running, this playback method won't work. When the audio
/* The following method is a fallback for other platforms to use the * mixer can handle playing streams while the core is paused, then
AI Service url to do the TTS. However, since the playback is done * we can use this.
via the audio mixer, which only processes the audio while the */
core is running, this playback method won't work. When the audio
mixer can handle playing streams while the core is paused, then
we can use this. */
#if 0 #if 0
#if defined(HAVE_NETWORKING) #if defined(HAVE_NETWORKING)
return accessibility_speak_ai_service(speak_text, voice, priority); return accessibility_speak_ai_service(speak_text, voice, priority);
#endif #endif
#endif #endif
} }
}
return true; return true;
} }
bool accessibility_speak_priority(
unsigned accessibility_narrator_speech_speed,
const char *speak_text,
int priority,
const char *voice)
{
frontend_ctx_driver_t *frontend =
frontend_state_get_ptr()->current_frontend_ctx;
RARCH_LOG("Spoke: %s\n", speak_text);
if (frontend && frontend->accessibility_speak)
return frontend->accessibility_speak(accessibility_narrator_speech_speed,
speak_text, priority, voice);
RARCH_LOG("Platform not supported for accessibility.\n");
return false;
}
#endif #endif

View File

@ -5311,7 +5311,7 @@ void runloop_msg_queue_push(const char *msg,
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*) msg, 0); (char*) msg, 0);
@ -7336,7 +7336,7 @@ void runloop_task_msg_queue_push(
if (is_accessibility_enabled( if (is_accessibility_enabled(
accessibility_enable, accessibility_enable,
access_st->enabled)) access_st->enabled))
accessibility_speak_priority( navigation_say(
accessibility_enable, accessibility_enable,
accessibility_narrator_speech_speed, accessibility_narrator_speech_speed,
(char*)msg, 0); (char*)msg, 0);

View File

@ -110,6 +110,151 @@ typedef struct
/* UTILITIES ---------------------------------------------------------------- */ /* UTILITIES ---------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/**
* Returns the string representation of the translation language enum value.
*/
static const char* ai_service_get_str(enum translation_lang id)
{
switch (id)
{
case TRANSLATION_LANG_EN:
return "en";
case TRANSLATION_LANG_ES:
return "es";
case TRANSLATION_LANG_FR:
return "fr";
case TRANSLATION_LANG_IT:
return "it";
case TRANSLATION_LANG_DE:
return "de";
case TRANSLATION_LANG_JP:
return "ja";
case TRANSLATION_LANG_NL:
return "nl";
case TRANSLATION_LANG_CS:
return "cs";
case TRANSLATION_LANG_DA:
return "da";
case TRANSLATION_LANG_SV:
return "sv";
case TRANSLATION_LANG_HR:
return "hr";
case TRANSLATION_LANG_KO:
return "ko";
case TRANSLATION_LANG_ZH_CN:
return "zh-CN";
case TRANSLATION_LANG_ZH_TW:
return "zh-TW";
case TRANSLATION_LANG_CA:
return "ca";
case TRANSLATION_LANG_BG:
return "bg";
case TRANSLATION_LANG_BN:
return "bn";
case TRANSLATION_LANG_EU:
return "eu";
case TRANSLATION_LANG_AZ:
return "az";
case TRANSLATION_LANG_AR:
return "ar";
case TRANSLATION_LANG_AST:
return "ast";
case TRANSLATION_LANG_SQ:
return "sq";
case TRANSLATION_LANG_AF:
return "af";
case TRANSLATION_LANG_EO:
return "eo";
case TRANSLATION_LANG_ET:
return "et";
case TRANSLATION_LANG_TL:
return "tl";
case TRANSLATION_LANG_FI:
return "fi";
case TRANSLATION_LANG_GL:
return "gl";
case TRANSLATION_LANG_KA:
return "ka";
case TRANSLATION_LANG_EL:
return "el";
case TRANSLATION_LANG_GU:
return "gu";
case TRANSLATION_LANG_HT:
return "ht";
case TRANSLATION_LANG_HE:
return "he";
case TRANSLATION_LANG_HI:
return "hi";
case TRANSLATION_LANG_HU:
return "hu";
case TRANSLATION_LANG_IS:
return "is";
case TRANSLATION_LANG_ID:
return "id";
case TRANSLATION_LANG_GA:
return "ga";
case TRANSLATION_LANG_KN:
return "kn";
case TRANSLATION_LANG_LA:
return "la";
case TRANSLATION_LANG_LV:
return "lv";
case TRANSLATION_LANG_LT:
return "lt";
case TRANSLATION_LANG_MK:
return "mk";
case TRANSLATION_LANG_MS:
return "ms";
case TRANSLATION_LANG_MT:
return "mt";
case TRANSLATION_LANG_NO:
return "no";
case TRANSLATION_LANG_FA:
return "fa";
case TRANSLATION_LANG_PL:
return "pl";
case TRANSLATION_LANG_PT:
return "pt";
case TRANSLATION_LANG_RO:
return "ro";
case TRANSLATION_LANG_RU:
return "ru";
case TRANSLATION_LANG_SR:
return "sr";
case TRANSLATION_LANG_SK:
return "sk";
case TRANSLATION_LANG_SL:
return "sl";
case TRANSLATION_LANG_SW:
return "sw";
case TRANSLATION_LANG_TA:
return "ta";
case TRANSLATION_LANG_TE:
return "te";
case TRANSLATION_LANG_TH:
return "th";
case TRANSLATION_LANG_TR:
return "tr";
case TRANSLATION_LANG_UK:
return "uk";
case TRANSLATION_LANG_BE:
return "be";
case TRANSLATION_LANG_UR:
return "ur";
case TRANSLATION_LANG_VI:
return "vi";
case TRANSLATION_LANG_CY:
return "cy";
case TRANSLATION_LANG_YI:
return "yi";
case TRANSLATION_LANG_DONT_CARE:
case TRANSLATION_LANG_LAST:
break;
}
return "";
}
/** /**
* Returns true if the accessibility narrator is currently playing audio. * Returns true if the accessibility narrator is currently playing audio.
*/ */
@ -156,8 +301,9 @@ static void accessibility_speak(const char *text)
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned speed = settings->uints.accessibility_narrator_speech_speed; unsigned speed = settings->uints.accessibility_narrator_speech_speed;
bool narrator_on = settings->bools.accessibility_enable; bool narrator_on = settings->bools.accessibility_enable;
const char* voice = ai_service_get_str(settings->uints.ai_service_target_lang);
accessibility_speak_priority(narrator_on, speed, text, 10); navigation_say(narrator_on, speed, text, 10);
#endif #endif
} }
@ -175,10 +321,11 @@ static void translation_speak(const char *text)
unsigned mode = settings->uints.ai_service_mode; unsigned mode = settings->uints.ai_service_mode;
unsigned speed = settings->uints.accessibility_narrator_speech_speed; unsigned speed = settings->uints.accessibility_narrator_speech_speed;
bool narrator_on = settings->bools.accessibility_enable; bool narrator_on = settings->bools.accessibility_enable;
const char* voice = ai_service_get_str(settings->uints.ai_service_target_lang);
/* Force the use of the narrator in Narrator modes (TTS) */ /* Force the use of the narrator in Narrator modes (TTS) */
if (mode == 2 || mode == 4 || mode == 5 || narrator_on || access_st->enabled) if (mode == 2 || mode == 4 || mode == 5 || narrator_on || access_st->enabled)
accessibility_speak_priority(true, speed, text, 10); accessibility_speak_priority(speed, text, 10, voice);
#endif #endif
} }
@ -329,151 +476,6 @@ void translation_release(bool inform)
translation_hash_info(MSG_AI_AUTO_MODE_DISABLED); translation_hash_info(MSG_AI_AUTO_MODE_DISABLED);
} }
/**
* Returns the string representation of the translation language enum value.
*/
static const char* ai_service_get_str(enum translation_lang id)
{
switch (id)
{
case TRANSLATION_LANG_EN:
return "en";
case TRANSLATION_LANG_ES:
return "es";
case TRANSLATION_LANG_FR:
return "fr";
case TRANSLATION_LANG_IT:
return "it";
case TRANSLATION_LANG_DE:
return "de";
case TRANSLATION_LANG_JP:
return "ja";
case TRANSLATION_LANG_NL:
return "nl";
case TRANSLATION_LANG_CS:
return "cs";
case TRANSLATION_LANG_DA:
return "da";
case TRANSLATION_LANG_SV:
return "sv";
case TRANSLATION_LANG_HR:
return "hr";
case TRANSLATION_LANG_KO:
return "ko";
case TRANSLATION_LANG_ZH_CN:
return "zh-CN";
case TRANSLATION_LANG_ZH_TW:
return "zh-TW";
case TRANSLATION_LANG_CA:
return "ca";
case TRANSLATION_LANG_BG:
return "bg";
case TRANSLATION_LANG_BN:
return "bn";
case TRANSLATION_LANG_EU:
return "eu";
case TRANSLATION_LANG_AZ:
return "az";
case TRANSLATION_LANG_AR:
return "ar";
case TRANSLATION_LANG_AST:
return "ast";
case TRANSLATION_LANG_SQ:
return "sq";
case TRANSLATION_LANG_AF:
return "af";
case TRANSLATION_LANG_EO:
return "eo";
case TRANSLATION_LANG_ET:
return "et";
case TRANSLATION_LANG_TL:
return "tl";
case TRANSLATION_LANG_FI:
return "fi";
case TRANSLATION_LANG_GL:
return "gl";
case TRANSLATION_LANG_KA:
return "ka";
case TRANSLATION_LANG_EL:
return "el";
case TRANSLATION_LANG_GU:
return "gu";
case TRANSLATION_LANG_HT:
return "ht";
case TRANSLATION_LANG_HE:
return "he";
case TRANSLATION_LANG_HI:
return "hi";
case TRANSLATION_LANG_HU:
return "hu";
case TRANSLATION_LANG_IS:
return "is";
case TRANSLATION_LANG_ID:
return "id";
case TRANSLATION_LANG_GA:
return "ga";
case TRANSLATION_LANG_KN:
return "kn";
case TRANSLATION_LANG_LA:
return "la";
case TRANSLATION_LANG_LV:
return "lv";
case TRANSLATION_LANG_LT:
return "lt";
case TRANSLATION_LANG_MK:
return "mk";
case TRANSLATION_LANG_MS:
return "ms";
case TRANSLATION_LANG_MT:
return "mt";
case TRANSLATION_LANG_NO:
return "no";
case TRANSLATION_LANG_FA:
return "fa";
case TRANSLATION_LANG_PL:
return "pl";
case TRANSLATION_LANG_PT:
return "pt";
case TRANSLATION_LANG_RO:
return "ro";
case TRANSLATION_LANG_RU:
return "ru";
case TRANSLATION_LANG_SR:
return "sr";
case TRANSLATION_LANG_SK:
return "sk";
case TRANSLATION_LANG_SL:
return "sl";
case TRANSLATION_LANG_SW:
return "sw";
case TRANSLATION_LANG_TA:
return "ta";
case TRANSLATION_LANG_TE:
return "te";
case TRANSLATION_LANG_TH:
return "th";
case TRANSLATION_LANG_TR:
return "tr";
case TRANSLATION_LANG_UK:
return "uk";
case TRANSLATION_LANG_BE:
return "be";
case TRANSLATION_LANG_UR:
return "ur";
case TRANSLATION_LANG_VI:
return "vi";
case TRANSLATION_LANG_CY:
return "cy";
case TRANSLATION_LANG_YI:
return "yi";
case TRANSLATION_LANG_DONT_CARE:
case TRANSLATION_LANG_LAST:
break;
}
return "";
}
/* AUTOMATION --------------------------------------------------------------- */ /* AUTOMATION --------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */