mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Enable TTS on demand, instead of fully disabling it when project setting is not set.
This commit is contained in:
@@ -245,37 +245,62 @@ String DisplayServerWayland::get_name() const {
|
||||
|
||||
#ifdef SPEECHD_ENABLED
|
||||
|
||||
void DisplayServerWayland::initialize_tts() const {
|
||||
const_cast<DisplayServerWayland *>(this)->tts = memnew(TTS_Linux);
|
||||
}
|
||||
|
||||
bool DisplayServerWayland::tts_is_speaking() const {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, false);
|
||||
return tts->is_speaking();
|
||||
}
|
||||
|
||||
bool DisplayServerWayland::tts_is_paused() const {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, false);
|
||||
return tts->is_paused();
|
||||
}
|
||||
|
||||
TypedArray<Dictionary> DisplayServerWayland::tts_get_voices() const {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, TypedArray<Dictionary>());
|
||||
return tts->get_voices();
|
||||
}
|
||||
|
||||
void DisplayServerWayland::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->speak(p_text, p_voice, p_volume, p_pitch, p_rate, p_utterance_id, p_interrupt);
|
||||
}
|
||||
|
||||
void DisplayServerWayland::tts_pause() {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->pause();
|
||||
}
|
||||
|
||||
void DisplayServerWayland::tts_resume() {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->resume();
|
||||
}
|
||||
|
||||
void DisplayServerWayland::tts_stop() {
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->stop();
|
||||
}
|
||||
@@ -1439,7 +1464,10 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
|
||||
|
||||
#ifdef SPEECHD_ENABLED
|
||||
// Init TTS
|
||||
tts = memnew(TTS_Linux);
|
||||
bool tts_enabled = GLOBAL_GET("audio/general/text_to_speech");
|
||||
if (tts_enabled) {
|
||||
initialize_tts();
|
||||
}
|
||||
#endif
|
||||
|
||||
rendering_driver = p_rendering_driver;
|
||||
|
||||
@@ -165,6 +165,8 @@ class DisplayServerWayland : public DisplayServer {
|
||||
|
||||
void try_suspend();
|
||||
|
||||
void initialize_tts() const;
|
||||
|
||||
public:
|
||||
virtual bool has_feature(Feature p_feature) const override;
|
||||
|
||||
|
||||
@@ -340,38 +340,63 @@ void DisplayServerX11::_flush_mouse_motion() {
|
||||
|
||||
#ifdef SPEECHD_ENABLED
|
||||
|
||||
void DisplayServerX11::initialize_tts() const {
|
||||
const_cast<DisplayServerX11 *>(this)->tts = memnew(TTS_Linux);
|
||||
}
|
||||
|
||||
bool DisplayServerX11::tts_is_speaking() const {
|
||||
ERR_FAIL_NULL_V_MSG(tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, false);
|
||||
return tts->is_speaking();
|
||||
}
|
||||
|
||||
bool DisplayServerX11::tts_is_paused() const {
|
||||
ERR_FAIL_NULL_V_MSG(tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, false);
|
||||
return tts->is_paused();
|
||||
}
|
||||
|
||||
TypedArray<Dictionary> DisplayServerX11::tts_get_voices() const {
|
||||
ERR_FAIL_NULL_V_MSG(tts, TypedArray<Dictionary>(), "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL_V(tts, TypedArray<Dictionary>());
|
||||
return tts->get_voices();
|
||||
}
|
||||
|
||||
void DisplayServerX11::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
||||
ERR_FAIL_NULL_MSG(tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->speak(p_text, p_voice, p_volume, p_pitch, p_rate, p_utterance_id, p_interrupt);
|
||||
}
|
||||
|
||||
void DisplayServerX11::tts_pause() {
|
||||
ERR_FAIL_NULL_MSG(tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->pause();
|
||||
}
|
||||
|
||||
void DisplayServerX11::tts_resume() {
|
||||
ERR_FAIL_NULL_MSG(tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->resume();
|
||||
}
|
||||
|
||||
void DisplayServerX11::tts_stop() {
|
||||
ERR_FAIL_NULL_MSG(tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
||||
if (unlikely(!tts)) {
|
||||
initialize_tts();
|
||||
}
|
||||
ERR_FAIL_NULL(tts);
|
||||
tts->stop();
|
||||
}
|
||||
|
||||
@@ -6781,7 +6806,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
|
||||
// Init TTS
|
||||
bool tts_enabled = GLOBAL_GET("audio/general/text_to_speech");
|
||||
if (tts_enabled) {
|
||||
tts = memnew(TTS_Linux);
|
||||
initialize_tts();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -394,6 +394,8 @@ class DisplayServerX11 : public DisplayServer {
|
||||
void _set_window_taskbar_pager_enabled(Window p_window, bool p_enabled);
|
||||
Rect2i _screens_get_full_rect() const;
|
||||
|
||||
void initialize_tts() const;
|
||||
|
||||
protected:
|
||||
void _window_changed(XEvent *event);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user