Skip to content

Commit

Permalink
Try to use speech-dispatcher linking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Debian authored and m1maker committed Oct 18, 2024
1 parent 39aa0cd commit c754e46
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ else()
find_package(X11 REQUIRED)
target_link_libraries(${PROJECT_NAME} ${X11_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_test ${X11_LIBRARIES})
find_package(PkgConfig REQUIRED)
pkg_check_modules(SpeechD REQUIRED speech-dispatcher)

target_link_libraries(${PROJECT_NAME} ${SpeechD_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_test ${SpeechD_LIBRARIES})

endif()

Expand Down
49 changes: 1 addition & 48 deletions SRC/SpeechDispatcher.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
#define spd_get_default_address (*spd_get_default_address)
#define spd_open2 (*spd_open2)
#define spd_close (*spd_close)
#define spd_say (*spd_say)
#define spd_stop (*spd_stop)
#define spd_cancel (*spd_cancel)
#define spd_set_voice_rate (*spd_set_voice_rate)
#define spd_get_voice_rate (*spd_get_voice_rate)
#define spd_set_volume (*spd_set_volume)
#define spd_get_volume (*spd_get_volume)
#define spd_pause_all (*spd_pause_all)
#define spd_resume_all (*spd_resume_all)

#include "SpeechDispatcher.h"
#undef spd_get_default_address
#undef spd_open2
#undef spd_close
#undef spd_say
#undef spd_stop
#undef spd_cancel
#undef spd_set_voice_rate
#undef spd_get_voice_rate
#undef spd_set_volume
#undef spd_get_volume
#undef spd_pause_all
#undef spd_resume_all


#include <dlfcn.h> // For dlopen, dlsym, dlclose
bool SpeechDispatcher::Initialize() {
Lib = dlopen("libspeechd.so", RTLD_LAZY);
if (Lib == nullptr) {
return false;
}

*(void**)&spd_get_default_address = dlsym(Lib, "spd_get_default_address");
*(void**)&spd_open2 = dlsym(Lib, "spd_open2");
*(void**)&spd_close = dlsym(Lib, "spd_close");
*(void**)&spd_say = dlsym(Lib, "spd_say");
*(void**)&spd_stop = dlsym(Lib, "spd_stop");
*(void**)&spd_cancel = dlsym(Lib, "spd_cancel");
*(void**)&spd_set_voice_rate = dlsym(Lib, "spd_set_voice_rate");
*(void**)&spd_get_voice_rate = dlsym(Lib, "spd_get_voice_rate");
*(void**)&spd_set_volume = dlsym(Lib, "spd_set_volume");
*(void**)&spd_get_volume = dlsym(Lib, "spd_get_volume");
*(void**)&spd_pause_all = dlsym(Lib, "spd_pause_all");
*(void**)&spd_resume_all = dlsym(Lib, "spd_resume_all");
const auto* address = spd_get_default_address(nullptr);
if (address == nullptr) {
return false;
Expand All @@ -60,11 +15,9 @@ bool SpeechDispatcher::GetActive() {
return Speech != nullptr;
}
bool SpeechDispatcher::Uninitialize() {
if (Lib == nullptr || Speech == nullptr)return false;
if (Speech == nullptr)return false;
spd_close(Speech);
Speech = nullptr;
dlclose(Lib);
Lib = nullptr;
return true;
}
bool SpeechDispatcher::Speak(const char* text, bool interrupt) {
Expand Down
1 change: 0 additions & 1 deletion SRC/SpeechDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class SpeechDispatcher : public Engine {

private:
SPDConnection* Speech = nullptr;
void* Lib = nullptr;
};

#endif

0 comments on commit c754e46

Please sign in to comment.