diff options
Diffstat (limited to 'platform/linuxbsd')
-rw-r--r-- | platform/linuxbsd/tts_linux.cpp | 130 | ||||
-rw-r--r-- | platform/linuxbsd/tts_linux.h | 6 | ||||
-rw-r--r-- | platform/linuxbsd/x11/display_server_x11.cpp | 3 | ||||
-rw-r--r-- | platform/linuxbsd/x11/key_mapping_x11.cpp | 8 |
4 files changed, 81 insertions, 66 deletions
diff --git a/platform/linuxbsd/tts_linux.cpp b/platform/linuxbsd/tts_linux.cpp index 04d7c5444f..ce0199e87f 100644 --- a/platform/linuxbsd/tts_linux.cpp +++ b/platform/linuxbsd/tts_linux.cpp @@ -76,76 +76,84 @@ void TTS_Linux::speech_init_thread_func(void *p_userdata) { void TTS_Linux::speech_event_index_mark(size_t p_msg_id, size_t p_client_id, SPDNotificationType p_type, char *p_index_mark) { TTS_Linux *tts = TTS_Linux::get_singleton(); - if (tts && tts->ids.has(p_msg_id)) { - MutexLock thread_safe_method(tts->_thread_safe_); - // Get word offset from the index mark injected to the text stream. - String mark = String::utf8(p_index_mark); - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, tts->ids[p_msg_id], mark.to_int()); + if (tts) { + callable_mp(tts, &TTS_Linux::_speech_index_mark).call_deferred(p_msg_id, p_client_id, (int)p_type, String::utf8(p_index_mark)); + } +} + +void TTS_Linux::_speech_index_mark(size_t p_msg_id, size_t p_client_id, int p_type, const String &p_index_mark) { + _THREAD_SAFE_METHOD_ + + if (ids.has(p_msg_id)) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_BOUNDARY, ids[p_msg_id], p_index_mark.to_int()); } } void TTS_Linux::speech_event_callback(size_t p_msg_id, size_t p_client_id, SPDNotificationType p_type) { TTS_Linux *tts = TTS_Linux::get_singleton(); if (tts) { - MutexLock thread_safe_method(tts->_thread_safe_); - List<DisplayServer::TTSUtterance> &queue = tts->queue; - if (!tts->paused && tts->ids.has(p_msg_id)) { - if (p_type == SPD_EVENT_END) { - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, tts->ids[p_msg_id]); - tts->ids.erase(p_msg_id); - tts->last_msg_id = -1; - tts->speaking = false; - } else if (p_type == SPD_EVENT_CANCEL) { - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, tts->ids[p_msg_id]); - tts->ids.erase(p_msg_id); - tts->last_msg_id = -1; - tts->speaking = false; - } + callable_mp(tts, &TTS_Linux::_speech_event).call_deferred(p_msg_id, p_client_id, (int)p_type); + } +} + +void TTS_Linux::_speech_event(size_t p_msg_id, size_t p_client_id, int p_type) { + _THREAD_SAFE_METHOD_ + + if (!paused && ids.has(p_msg_id)) { + if ((SPDNotificationType)p_type == SPD_EVENT_END) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_ENDED, ids[p_msg_id]); + ids.erase(p_msg_id); + last_msg_id = -1; + speaking = false; + } else if ((SPDNotificationType)p_type == SPD_EVENT_CANCEL) { + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, ids[p_msg_id]); + ids.erase(p_msg_id); + last_msg_id = -1; + speaking = false; } - if (!tts->speaking && queue.size() > 0) { - DisplayServer::TTSUtterance &message = queue.front()->get(); - - // Inject index mark after each word. - String text; - String language; - SPDVoice **voices = spd_list_synthesis_voices(tts->synth); - if (voices != nullptr) { - SPDVoice **voices_ptr = voices; - while (*voices_ptr != nullptr) { - if (String::utf8((*voices_ptr)->name) == message.voice) { - language = String::utf8((*voices_ptr)->language); - break; - } - voices_ptr++; - } - free_spd_voices(voices); - } - PackedInt32Array breaks = TS->string_get_word_breaks(message.text, language); - for (int i = 0; i < breaks.size(); i += 2) { - const int start = breaks[i]; - const int end = breaks[i + 1]; - text += message.text.substr(start, end - start + 1); - text += "<mark name=\"" + String::num_int64(end, 10) + "\"/>"; - } + } + if (!speaking && queue.size() > 0) { + DisplayServer::TTSUtterance &message = queue.front()->get(); - spd_set_synthesis_voice(tts->synth, message.voice.utf8().get_data()); - spd_set_volume(tts->synth, message.volume * 2 - 100); - spd_set_voice_pitch(tts->synth, (message.pitch - 1) * 100); - float rate = 0; - if (message.rate > 1.f) { - rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100; - } else if (message.rate < 1.f) { - rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100; + // Inject index mark after each word. + String text; + String language; + SPDVoice **voices = spd_list_synthesis_voices(synth); + if (voices != nullptr) { + SPDVoice **voices_ptr = voices; + while (*voices_ptr != nullptr) { + if (String::utf8((*voices_ptr)->name) == message.voice) { + language = String::utf8((*voices_ptr)->language); + break; + } + voices_ptr++; } - spd_set_voice_rate(tts->synth, rate); - spd_set_data_mode(tts->synth, SPD_DATA_SSML); - tts->last_msg_id = spd_say(tts->synth, SPD_TEXT, text.utf8().get_data()); - tts->ids[tts->last_msg_id] = message.id; - DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, message.id); - - queue.pop_front(); - tts->speaking = true; + free_spd_voices(voices); + } + PackedInt32Array breaks = TS->string_get_word_breaks(message.text, language); + for (int i = 0; i < breaks.size(); i += 2) { + const int start = breaks[i]; + const int end = breaks[i + 1]; + text += message.text.substr(start, end - start + 1); + text += "<mark name=\"" + String::num_int64(end, 10) + "\"/>"; } + spd_set_synthesis_voice(synth, message.voice.utf8().get_data()); + spd_set_volume(synth, message.volume * 2 - 100); + spd_set_voice_pitch(synth, (message.pitch - 1) * 100); + float rate = 0; + if (message.rate > 1.f) { + rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100; + } else if (message.rate < 1.f) { + rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100; + } + spd_set_voice_rate(synth, rate); + spd_set_data_mode(synth, SPD_DATA_SSML); + last_msg_id = spd_say(synth, SPD_TEXT, text.utf8().get_data()); + ids[last_msg_id] = message.id; + DisplayServer::get_singleton()->tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_STARTED, message.id); + + queue.pop_front(); + speaking = true; } } @@ -204,7 +212,7 @@ void TTS_Linux::speak(const String &p_text, const String &p_voice, int p_volume, if (is_paused()) { resume(); } else { - speech_event_callback(0, 0, SPD_EVENT_BEGIN); + _speech_event(0, 0, (int)SPD_EVENT_BEGIN); } } diff --git a/platform/linuxbsd/tts_linux.h b/platform/linuxbsd/tts_linux.h index 3fe7b659d0..4134f8fa2f 100644 --- a/platform/linuxbsd/tts_linux.h +++ b/platform/linuxbsd/tts_linux.h @@ -45,7 +45,7 @@ #include <libspeechd.h> #endif -class TTS_Linux { +class TTS_Linux : public Object { _THREAD_SAFE_CLASS_ List<DisplayServer::TTSUtterance> queue; @@ -63,6 +63,10 @@ class TTS_Linux { static TTS_Linux *singleton; +protected: + void _speech_event(size_t p_msg_id, size_t p_client_id, int p_type); + void _speech_index_mark(size_t p_msg_id, size_t p_client_id, int p_type, const String &p_index_mark); + public: static TTS_Linux *get_singleton(); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index dff2f536a8..d1f1115aad 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -5258,6 +5258,9 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode } #ifdef XKB_ENABLED xkb_loaded = (initialize_xkbcommon(dylibloader_verbose) == 0); + if (!xkb_context_new || !xkb_compose_table_new_from_locale || !xkb_compose_table_unref || !xkb_context_unref || !xkb_compose_state_feed || !xkb_compose_state_unref || !xkb_compose_state_new || !xkb_compose_state_get_status || !xkb_compose_state_get_utf8 || !xkb_keysym_to_utf32 || !xkb_keysym_to_upper) { + xkb_loaded = false; + } #endif if (initialize_xext(dylibloader_verbose) != 0) { r_error = ERR_UNAVAILABLE; diff --git a/platform/linuxbsd/x11/key_mapping_x11.cpp b/platform/linuxbsd/x11/key_mapping_x11.cpp index e5eba6ccad..fe73162280 100644 --- a/platform/linuxbsd/x11/key_mapping_x11.cpp +++ b/platform/linuxbsd/x11/key_mapping_x11.cpp @@ -217,8 +217,8 @@ void KeyMappingX11::initialize() { scancode_map[0x1F] = Key::I; scancode_map[0x20] = Key::O; scancode_map[0x21] = Key::P; - scancode_map[0x22] = Key::BRACELEFT; - scancode_map[0x23] = Key::BRACERIGHT; + scancode_map[0x22] = Key::BRACKETLEFT; + scancode_map[0x23] = Key::BRACKETRIGHT; scancode_map[0x24] = Key::ENTER; scancode_map[0x25] = Key::CTRL; scancode_map[0x26] = Key::A; @@ -232,7 +232,7 @@ void KeyMappingX11::initialize() { scancode_map[0x2E] = Key::L; scancode_map[0x2F] = Key::SEMICOLON; scancode_map[0x30] = Key::APOSTROPHE; - scancode_map[0x31] = Key::SECTION; + scancode_map[0x31] = Key::QUOTELEFT; scancode_map[0x32] = Key::SHIFT; scancode_map[0x33] = Key::BACKSLASH; scancode_map[0x34] = Key::Z; @@ -275,7 +275,7 @@ void KeyMappingX11::initialize() { scancode_map[0x59] = Key::KP_3; scancode_map[0x5A] = Key::KP_0; scancode_map[0x5B] = Key::KP_PERIOD; - scancode_map[0x5E] = Key::QUOTELEFT; + scancode_map[0x5E] = Key::SECTION; scancode_map[0x5F] = Key::F11; scancode_map[0x60] = Key::F12; scancode_map[0x68] = Key::KP_ENTER; |