a11y: linux tts with espeak-ng

This commit is contained in:
Demur Rumed 2025-04-19 01:41:44 +00:00
parent 52a3058926
commit 4b71dda3ab
6 changed files with 69 additions and 14 deletions

View file

@ -1 +1 @@
libusb-dev libusb-1.0-0-dev libsdl2-dev libsdl2-net-dev libpng-dev libglew-dev nlohmann-json3-dev libtinyxml2-dev libspdlog-dev ninja-build
libusb-dev libusb-1.0-0-dev libsdl2-dev libsdl2-net-dev libpng-dev libglew-dev nlohmann-json3-dev libtinyxml2-dev libspdlog-dev libespeak-ng-dev ninja-build

View file

@ -141,16 +141,21 @@ endif()
# handle Network removals
if (!BUILD_REMOTE_CONTROL)
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/crowd-control/*")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/crowd-control/")
endif()
# handle speechsynthesizer removals
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/Darwin*")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/Darwin")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/SAPI*")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/SAPI")
else()
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/(Darwin|SAPI).*")
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/(Darwin|SAPI)")
endif()
find_library(ESPEAK espeak-ng)
if (NOT ESPEAK)
list(FILTER soh__ EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/ESpeak")
endif()
# soh/Extractor {{{
@ -176,12 +181,12 @@ file(GLOB_RECURSE src__ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.c" "src/*.h"
set_source_files_properties(${src__} PROPERTIES COMPILE_OPTIONS "${WARNING_OVERRIDE}")
list(APPEND src__ ${CMAKE_CURRENT_SOURCE_DIR}/Resource.rc)
list(FILTER src__ EXCLUDE REGEX "src/dmadata/*")
list(FILTER src__ EXCLUDE REGEX "src/elf_message/*")
list(FILTER src__ EXCLUDE REGEX "src/libultra/io/*")
list(FILTER src__ EXCLUDE REGEX "src/libultra/libc/*")
list(FILTER src__ EXCLUDE REGEX "src/libultra/os/*")
list(FILTER src__ EXCLUDE REGEX "src/libultra/rmon/*")
list(FILTER src__ EXCLUDE REGEX "src/dmadata/")
list(FILTER src__ EXCLUDE REGEX "src/elf_message/")
list(FILTER src__ EXCLUDE REGEX "src/libultra/io/")
list(FILTER src__ EXCLUDE REGEX "src/libultra/libc/")
list(FILTER src__ EXCLUDE REGEX "src/libultra/os/")
list(FILTER src__ EXCLUDE REGEX "src/libultra/rmon/")
list(APPEND src__ "src/libultra/libc/sprintf.c")
list(REMOVE_ITEM src__ "src/libultra/gu/cosf.c")
list(REMOVE_ITEM src__ "src/libultra/gu/lookat.c")
@ -317,6 +322,11 @@ if (BUILD_REMOTE_CONTROL)
endif()
endif()
if (ESPEAK)
add_compile_definitions(ESPEAK=1)
target_link_libraries(${PROJECT_NAME} PUBLIC espeak-ng)
endif()
target_include_directories(${PROJECT_NAME} PRIVATE assets
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/src/

View file

@ -0,0 +1,26 @@
#include "ESpeakSpeechSynthesizer.h"
extern "C" {
#include <espeak-ng/speak_lib.h>
}
ESpeakSpeechSynthesizer::ESpeakSpeechSynthesizer() {
}
bool ESpeakSpeechSynthesizer::DoInit() {
return espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 100, NULL, 0) != -1;
}
void ESpeakSpeechSynthesizer::DoUninitialize() {
espeak_Terminate();
}
void ESpeakSpeechSynthesizer::Speak(const char* text, const char* language) {
if (language != this->mLanguage) {
espeak_VOICE voice = { .languages = language };
if (espeak_SetVoiceByProperties(&voice)) {
return;
}
this->mLanguage = language;
}
espeak_Synth(text, 100, 0, POS_CHARACTER, 0, espeakCHARS_UTF8, NULL, NULL);
}

View file

@ -0,0 +1,17 @@
#pragma once
#include "SpeechSynthesizer.h"
class ESpeakSpeechSynthesizer : public SpeechSynthesizer {
public:
ESpeakSpeechSynthesizer();
void Speak(const char* text, const char* language);
protected:
bool DoInit(void);
void DoUninitialize(void);
private:
const char* mLanguage;
};

View file

@ -35,6 +35,8 @@ class SpeechSynthesizer {
#include "SAPISpeechSynthesizer.h"
#elif defined(__APPLE__)
#include "DarwinSpeechSynthesizer.h"
#elif ESPEAK
#include "ESpeakSpeechSynthesizer.h"
#endif
#include "SpeechLogger.h"

View file

@ -1224,14 +1224,14 @@ extern "C" void InitOTR() {
ActorDB::Instance = new ActorDB();
#ifdef __APPLE__
SpeechSynthesizer::Instance = new DarwinSpeechSynthesizer();
SpeechSynthesizer::Instance->Init();
#elif defined(_WIN32)
SpeechSynthesizer::Instance = new SAPISpeechSynthesizer();
SpeechSynthesizer::Instance->Init();
#elif ESPEAK
SpeechSynthesizer::Instance = new ESpeakSpeechSynthesizer();
#else
SpeechSynthesizer::Instance = new SpeechLogger();
SpeechSynthesizer::Instance->Init();
#endif
SpeechSynthesizer::Instance->Init();
#ifdef ENABLE_REMOTE_CONTROL
CrowdControl::Instance = new CrowdControl();