mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
macOS/iOS/tvOS: enable text-to-speech using AVSpeechSynthesizer.
Fixes #16532.
This commit is contained in:
parent
87b643f487
commit
79b71179a5
frontend/drivers
griffin
input/drivers_joypad
ui/drivers/cocoa
@ -26,6 +26,7 @@
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CFArray.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../../config.h"
|
||||
@ -820,7 +821,7 @@ static enum retro_language frontend_darwin_get_user_language(void)
|
||||
return retroarch_get_language_from_iso(s);
|
||||
}
|
||||
|
||||
#if (defined(OSX) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101200))
|
||||
#if defined(OSX)
|
||||
static char* accessibility_mac_language_code(const char* language)
|
||||
{
|
||||
if (string_is_equal(language,"en"))
|
||||
@ -901,10 +902,6 @@ static bool accessibility_speak_macos(int speed,
|
||||
char* language_speaker = accessibility_mac_language_code(voice);
|
||||
char* speeds[10] = {"80", "100", "125", "150", "170", "210",
|
||||
"260", "310", "380", "450"};
|
||||
if (speed < 1)
|
||||
speed = 1;
|
||||
else if (speed > 10)
|
||||
speed = 10;
|
||||
|
||||
if (priority < 10 && speak_pid > 0)
|
||||
{
|
||||
@ -954,8 +951,60 @@ static bool accessibility_speak_macos(int speed,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static bool frontend_darwin_is_narrator_running(void)
|
||||
{
|
||||
if (@available(macOS 10.14, iOS 7, tvOS 9, *))
|
||||
return true;
|
||||
#if OSX
|
||||
return is_narrator_running_macos();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool frontend_darwin_accessibility_speak(int speed,
|
||||
const char* speak_text, int priority)
|
||||
{
|
||||
if (speed < 1)
|
||||
speed = 1;
|
||||
else if (speed > 10)
|
||||
speed = 10;
|
||||
|
||||
if (@available(macOS 10.14, iOS 7, tvOS 9, *))
|
||||
{
|
||||
static dispatch_once_t once;
|
||||
static AVSpeechSynthesizer *synth;
|
||||
dispatch_once(&once, ^{
|
||||
synth = [[AVSpeechSynthesizer alloc] init];
|
||||
});
|
||||
if ([synth isSpeaking])
|
||||
{
|
||||
if (priority < 10)
|
||||
return true;
|
||||
else
|
||||
[synth stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
|
||||
}
|
||||
|
||||
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:[NSString stringWithUTF8String:speak_text]];
|
||||
if (!utterance)
|
||||
return false;
|
||||
utterance.rate = (float)speed / 10.0f;
|
||||
const char *language = get_user_language_iso639_1(false);
|
||||
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:[NSString stringWithUTF8String:language]];
|
||||
[synth speakUtterance:utterance];
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(OSX)
|
||||
return accessibility_speak_macos(speed, speak_text, priority);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
frontend_ctx_driver_t frontend_ctx_darwin = {
|
||||
frontend_darwin_get_env, /* get_env */
|
||||
NULL, /* init */
|
||||
@ -987,13 +1036,8 @@ frontend_ctx_driver_t frontend_ctx_darwin = {
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
frontend_darwin_get_cpu_model_name, /* get_cpu_model_name */
|
||||
frontend_darwin_get_user_language, /* get_user_language */
|
||||
#if (defined(OSX) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101200))
|
||||
is_narrator_running_macos, /* is_narrator_running */
|
||||
accessibility_speak_macos, /* accessibility_speak */
|
||||
#else
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
#endif
|
||||
frontend_darwin_is_narrator_running, /* is_narrator_running */
|
||||
frontend_darwin_accessibility_speak, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"darwin", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
|
@ -27,10 +27,6 @@
|
||||
#define HAVE_COMPRESSION 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include "../frontend/drivers/platform_darwin.m"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOATOUCH) || defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
|
||||
|
||||
#include "../ui/drivers/cocoa/cocoa_common.m"
|
||||
@ -55,6 +51,10 @@
|
||||
#include "../input/drivers_joypad/mfi_joypad.m"
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include "../frontend/drivers/platform_darwin.m"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COREAUDIO3
|
||||
#include "../audio/drivers/coreaudio3.m"
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
#include "../input_driver.h"
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
|
||||
#import <GameController/GameController.h>
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "../../../configuration.h"
|
||||
#include "../../../content.h"
|
||||
#include "../../../core_info.h"
|
||||
#include "../../../defaults.h"
|
||||
#include "../../../file_path_special.h"
|
||||
#include "../../../menu/menu_cbs.h"
|
||||
#include "../../../paths.h"
|
||||
#include "../../../retroarch.h"
|
||||
@ -49,6 +51,10 @@
|
||||
#include "../../input/drivers/cocoa_input.h"
|
||||
#include "../../input/drivers_keyboard/keyboard_event_apple.h"
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "../../menu/menu_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH)
|
||||
id<ApplePlatform> apple_platform;
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user