Skip to content

Commit

Permalink
Update to compile with Godot 3.5
Browse files Browse the repository at this point in the history
Main change is the Threading API changes.
ALSA linking issues on Ubuntu, added some "-lasound"
ERR_PRINTS -> ERR_PRINT
Known issue, doesn't compile: scons platform=windows speech_to_text_shared="yes"
  • Loading branch information
menip committed Aug 27, 2022
1 parent 6dc3d2c commit 01efcb3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
5 changes: 3 additions & 2 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ if platform == "x11":
base_srcs.append("libsphinxad/ad_pulse.c")
elif os.system("pkg-config --exists alsa") == 0:
base_srcs.append("libsphinxad/ad_alsa.c")
env.Append(LIBS=["-lasound"])
else:
print("[Speech to Text] Error: No PulseAudio or ALSA support found!")
Exit(1)
Expand Down Expand Up @@ -163,8 +164,8 @@ all_srcs = base_srcs + pocket_srcs + stt_srcs

if ARGUMENTS.get('speech_to_text_shared', 'no') == 'yes':
# Shared lib compilation
module_env.Append(CXXFLAGS='-fPIC') # Shared library flag
module_env['LIBS'] = []
module_env.Append(CXXFLAGS=['-fPIC']) # Shared library flag
module_env['LIBS'] = ["-lasound"] if platform == 'x11' else []

shared_lib = module_env.SharedLibrary(target='#bin/speech_to_text',
source=all_srcs)
Expand Down
10 changes: 5 additions & 5 deletions file_dir_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool FileDirUtil::create_dir_safe(String path, String dirname) {
else {
err = da->make_dir(dirname);
if (err != OK)
ERR_PRINTS("Couldn't create '" + dirname + "' directory in '" +
ERR_PRINT("Couldn't create '" + dirname + "' directory in '" +
path + "'");
}

Expand All @@ -26,7 +26,7 @@ bool FileDirUtil::copy_file(String from, String to) {
String to_target = to.plus_file(from_basename);

if (da->copy(from, to_target) != OK) {
ERR_PRINTS("Couldn't copy '" + from + "' to '" + to_target + "'");
ERR_PRINT("Couldn't copy '" + from + "' to '" + to_target + "'");
memdelete(da);
return false;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ bool FileDirUtil::remove_dir_recursive(String dirname) {
DirAccess *da = DirAccess::open(dirname);

if (!DirAccess::exists(dirname)) {
ERR_PRINTS("Directory '" + dirname + "' not found");
ERR_PRINT("Directory '" + dirname + "' not found");
memdelete(da);
return false;
}
Expand All @@ -100,7 +100,7 @@ bool FileDirUtil::remove_dir_recursive(String dirname) {
remove_dir_recursive(dirname.plus_file(filename));
// Regular file; remove normally
else if (da->remove(filename) != OK) {
ERR_PRINTS("Couldn't delete '" + filename + "' in '" + dirname + "'");
ERR_PRINT("Couldn't delete '" + filename + "' in '" + dirname + "'");
memdelete(da);
return false;
}
Expand All @@ -111,7 +111,7 @@ bool FileDirUtil::remove_dir_recursive(String dirname) {
// Delete empty "dirname" directory
Error err = da->remove(dirname);
if (err != OK)
ERR_PRINTS("Couldn't delete '" + dirname + "'");
ERR_PRINT("Couldn't delete '" + dirname + "'");

memdelete(da);
return err == OK;
Expand Down
6 changes: 3 additions & 3 deletions stt_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void STTConfig::set_hmm_dirname(const String &hmm_dirname) {
if (DirAccess::exists(hmm_dirname))
this->hmm_dirname = hmm_dirname;
else
ERR_PRINTS("Directory '" + hmm_dirname + "' not found!");
ERR_PRINT("Directory '" + hmm_dirname + "' not found!");
}

String STTConfig::get_hmm_dirname() const {
Expand All @@ -148,7 +148,7 @@ void STTConfig::set_dict_filename(const String &dict_filename) {
if (FileAccess::exists(dict_filename))
this->dict_filename = dict_filename;
else
ERR_PRINTS("File '" + dict_filename + "' not found!");
ERR_PRINT("File '" + dict_filename + "' not found!");
}

String STTConfig::get_dict_filename() const {
Expand All @@ -159,7 +159,7 @@ void STTConfig::set_kws_filename(const String &kws_filename) {
if (FileAccess::exists(kws_filename))
this->kws_filename = kws_filename;
else
ERR_PRINTS("File '" + kws_filename + "' not found!");
ERR_PRINT("File '" + kws_filename + "' not found!");
}

String STTConfig::get_kws_filename() const {
Expand Down
2 changes: 1 addition & 1 deletion stt_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


// Shortcut for printing STTError::Error values with ERR_PRINT()
#define STT_ERR_PRINTS(e) ERR_PRINTS(STTError::get_singleton()->get_error_string(e));
#define STT_ERR_PRINTS(e) ERR_PRINT(STTError::get_singleton()->get_error_string(e));

class STTError : public Object {
GDCLASS(STTError, Object);
Expand Down
15 changes: 6 additions & 9 deletions stt_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ STTError::Error STTRunner::start() {
is_running = true;

reset_run_error();
recognition = Thread::create(STTRunner::_thread_recognize, this);
recognition.start(STTRunner::_thread_recognize, this);

return STTError::OK;
}
Expand All @@ -26,11 +26,9 @@ bool STTRunner::running() {
}

void STTRunner::stop() {
if (recognition != NULL) {
if (recognition.is_started()) {
is_running = false;
Thread::wait_to_finish(recognition);
memdelete(recognition);
recognition = NULL;
recognition.wait_to_finish();
}
}

Expand Down Expand Up @@ -177,16 +175,15 @@ void STTRunner::_bind_methods() {
}

STTRunner::STTRunner() {
recognition = NULL;
recognition.wait_to_finish(); //TODO maybe just don't need
is_running = false;
rec_buffer_size = DEFAULT_REC_BUFFER_SIZE;
reset_run_error();
}

STTRunner::~STTRunner() {
if (recognition != NULL) {
if (recognition.is_started()) {
is_running = false;
Thread::wait_to_finish(recognition);
memdelete(recognition);
recognition.wait_to_finish();
}
}
2 changes: 1 addition & 1 deletion stt_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class STTRunner : public Node {
GDCLASS(STTRunner, Node);

private:
Thread *recognition; // Used to run the speech recognition in parallel
Thread recognition; // Used to run the speech recognition in parallel
bool is_running; // If true, speech recognition loop is currently on

Ref<STTConfig> config;
Expand Down

0 comments on commit 01efcb3

Please sign in to comment.