diff --git a/runtime/core/bin/http_server_main.cc b/runtime/core/bin/http_server_main.cc index 7609ffd..3d71d88 100644 --- a/runtime/core/bin/http_server_main.cc +++ b/runtime/core/bin/http_server_main.cc @@ -12,16 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gflags/gflags.h" -#include "glog/logging.h" +#include -#include "http/http_server.h" -#include "processor/wetext_processor.h" +#include "gflags/gflags.h" #include "frontend/g2p_en.h" #include "frontend/g2p_prosody.h" #include "frontend/wav.h" +#include "http/http_server.h" #include "model/tts_model.h" +#include "processor/wetext_processor.h" +#include "utils/log.h" #include "utils/string.h" // Flags @@ -52,7 +53,6 @@ DEFINE_string(phone2id, "", "phone to id"); DEFINE_string(vits_model, "", "e2e tts model file"); DEFINE_int32(sampling_rate, 22050, "sampling rate of pcm"); - // port DEFINE_int32(port, 10086, "http listening port"); diff --git a/runtime/core/bin/tts_main.cc b/runtime/core/bin/tts_main.cc index bf78c86..e1b0030 100644 --- a/runtime/core/bin/tts_main.cc +++ b/runtime/core/bin/tts_main.cc @@ -16,7 +16,7 @@ #include #include "gflags/gflags.h" -#include "glog/logging.h" +#include "utils/log.h" #include "processor/wetext_processor.h" #include "frontend/g2p_en.h" diff --git a/runtime/core/frontend/g2p_en.cc b/runtime/core/frontend/g2p_en.cc index 6141471..87d471e 100644 --- a/runtime/core/frontend/g2p_en.cc +++ b/runtime/core/frontend/g2p_en.cc @@ -17,7 +17,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "utils/fst.h" #include "utils/string.h" diff --git a/runtime/core/frontend/g2p_prosody.cc b/runtime/core/frontend/g2p_prosody.cc index fe7057d..05d29d6 100644 --- a/runtime/core/frontend/g2p_prosody.cc +++ b/runtime/core/frontend/g2p_prosody.cc @@ -21,7 +21,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" #include "utils/utils.h" diff --git a/runtime/core/frontend/lexicon.cc b/runtime/core/frontend/lexicon.cc index 9429158..4ce2347 100644 --- a/runtime/core/frontend/lexicon.cc +++ b/runtime/core/frontend/lexicon.cc @@ -20,7 +20,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" diff --git a/runtime/core/frontend/sandhi.cc b/runtime/core/frontend/sandhi.cc index 15f4f00..2e7f151 100644 --- a/runtime/core/frontend/sandhi.cc +++ b/runtime/core/frontend/sandhi.cc @@ -17,7 +17,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" diff --git a/runtime/core/frontend/sentence_break.cc b/runtime/core/frontend/sentence_break.cc index 3b47107..01d8b7e 100644 --- a/runtime/core/frontend/sentence_break.cc +++ b/runtime/core/frontend/sentence_break.cc @@ -19,7 +19,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" diff --git a/runtime/core/frontend/wav.h b/runtime/core/frontend/wav.h index 0a882f5..54fde2d 100644 --- a/runtime/core/frontend/wav.h +++ b/runtime/core/frontend/wav.h @@ -23,7 +23,7 @@ #include -#include "glog/logging.h" +#include "utils/log.h" namespace wetts { diff --git a/runtime/core/frontend/word_break.cc b/runtime/core/frontend/word_break.cc index 7a83104..895421f 100644 --- a/runtime/core/frontend/word_break.cc +++ b/runtime/core/frontend/word_break.cc @@ -20,7 +20,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" namespace wetts { diff --git a/runtime/core/model/onnx_model.cc b/runtime/core/model/onnx_model.cc index 05f5527..4362b71 100644 --- a/runtime/core/model/onnx_model.cc +++ b/runtime/core/model/onnx_model.cc @@ -20,7 +20,7 @@ #include "model/onnx_model.h" -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" diff --git a/runtime/core/model/tts.cc b/runtime/core/model/tts.cc index 500ff59..b5a722d 100644 --- a/runtime/core/model/tts.cc +++ b/runtime/core/model/tts.cc @@ -23,7 +23,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" #include "frontend/sentence_break.h" #include "utils/string.h" diff --git a/runtime/core/model/vits_model.cc b/runtime/core/model/vits_model.cc index b7ee8b2..37441b4 100644 --- a/runtime/core/model/vits_model.cc +++ b/runtime/core/model/vits_model.cc @@ -20,7 +20,7 @@ #include #include -#include "glog/logging.h" +#include "utils/log.h" namespace wetts { diff --git a/runtime/core/utils/CMakeLists.txt b/runtime/core/utils/CMakeLists.txt index 7417d52..58074b2 100644 --- a/runtime/core/utils/CMakeLists.txt +++ b/runtime/core/utils/CMakeLists.txt @@ -4,4 +4,10 @@ add_library(utils STATIC utils.cc ) -target_link_libraries(utils PUBLIC glog fst) +if(ANDROID) + find_library(alog log) # andorid log + target_link_libraries(utils PUBLIC ${alog}) +else() + # For non-Android platforms, link glog + target_link_libraries(utils PUBLIC glog) +endif() diff --git a/runtime/core/utils/fst.h b/runtime/core/utils/fst.h index e7c58e9..2379bcc 100644 --- a/runtime/core/utils/fst.h +++ b/runtime/core/utils/fst.h @@ -19,7 +19,7 @@ #include #include "fst/fstlib.h" -#include "glog/logging.h" +#include "utils/log.h" #include "utils/string.h" diff --git a/runtime/core/utils/log.h b/runtime/core/utils/log.h new file mode 100644 index 0000000..d568302 --- /dev/null +++ b/runtime/core/utils/log.h @@ -0,0 +1,147 @@ +// Copyright (c) 2025 Binbin Zhang (binbzha@qq.com) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef UTILS_LOG_H_ +#define UTILS_LOG_H_ + +#ifndef __ANDROID__ +#include "glog/logging.h" +#else + +#include +#include +#include + +// Android Log Tag +#ifndef LOG_TAG +#define LOG_TAG "wetts" +#endif + +// Log levels mapping to Android log levels +#define ANDROID_LOG_VERBOSE 2 +#define ANDROID_LOG_DEBUG 3 +#define ANDROID_LOG_INFO 4 +#define ANDROID_LOG_WARN 5 +#define ANDROID_LOG_ERROR 6 +#define ANDROID_LOG_FATAL 7 + +// Helper class for stream-based logging +class AndroidLogMessage { + public: + AndroidLogMessage(int level, const char* file, int line) + : level_(level), file_(file), line_(line) {} + + ~AndroidLogMessage() { + std::string message = stream_.str(); + if (!message.empty() && message.back() == '\n') { + message.pop_back(); + } + __android_log_print(level_, LOG_TAG, "[%s:%d] %s", file_, line_, + message.c_str()); + } + + std::ostream& stream() { return stream_; } + + private: + int level_; + const char* file_; + int line_; + std::ostringstream stream_; +}; + +// Helper class for VLOG +class AndroidVLogMessage { + public: + AndroidVLogMessage(int level, const char* file, int line) + : level_(level), file_(file), line_(line) {} + + ~AndroidVLogMessage() { + std::string message = stream_.str(); + if (!message.empty() && message.back() == '\n') { + message.pop_back(); + } + // VLOG maps to DEBUG level in Android + __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "[%s:%d] VLOG(%d) %s", + file_, line_, level_, message.c_str()); + } + + std::ostream& stream() { return stream_; } + + private: + int level_; + const char* file_; + int line_; + std::ostringstream stream_; +}; + +// Helper function to get filename from path +inline const char* GetFileName(const char* path) { + const char* filename = path; + const char* last_slash = strrchr(path, '/'); + if (last_slash != nullptr) { + filename = last_slash + 1; + } + return filename; +} + +// LOG macros +#define LOG(severity) \ + AndroidLogMessage(ANDROID_LOG_##severity, GetFileName(__FILE__), __LINE__) \ + .stream() + +// VLOG macros +#define VLOG(verboselevel) \ + AndroidVLogMessage(verboselevel, GetFileName(__FILE__), __LINE__).stream() + +// CHECK macros +#define CHECK(condition) \ + if (!(condition)) \ + AndroidLogMessage(ANDROID_LOG_FATAL, GetFileName(__FILE__), __LINE__) \ + .stream() \ + << "Check failed: " #condition " " + +#define CHECK_EQ(val1, val2) CHECK((val1) == (val2)) +#define CHECK_NE(val1, val2) CHECK((val1) != (val2)) +#define CHECK_LE(val1, val2) CHECK((val1) <= (val2)) +#define CHECK_LT(val1, val2) CHECK((val1) < (val2)) +#define CHECK_GE(val1, val2) CHECK((val1) >= (val2)) +#define CHECK_GT(val1, val2) CHECK((val1) > (val2)) + +// DCHECK macros (same as CHECK in release builds) +#ifdef NDEBUG +#define DCHECK(condition) \ + while (false) \ + AndroidLogMessage(ANDROID_LOG_FATAL, GetFileName(__FILE__), __LINE__).stream() +#define DCHECK_EQ(val1, val2) DCHECK((val1) == (val2)) +#define DCHECK_NE(val1, val2) DCHECK((val1) != (val2)) +#define DCHECK_LE(val1, val2) DCHECK((val1) <= (val2)) +#define DCHECK_LT(val1, val2) DCHECK((val1) < (val2)) +#define DCHECK_GE(val1, val2) DCHECK((val1) >= (val2)) +#define DCHECK_GT(val1, val2) DCHECK((val1) > (val2)) +#else +#define DCHECK(condition) CHECK(condition) +#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2) +#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2) +#define DCHECK_LE(val1, val2) CHECK_LE(val1, val2) +#define DCHECK_LT(val1, val2) CHECK_LT(val1, val2) +#define DCHECK_GE(val1, val2) CHECK_GE(val1, val2) +#define DCHECK_GT(val1, val2) CHECK_GT(val1, val2) +#endif + +// Empty implementations for glog initialization functions +inline void InitGoogleLogging(const char*) {} +inline void ShutdownGoogleLogging() {} + +#endif +#endif // UTILS_LOG_H_ diff --git a/runtime/core/utils/utils.cc b/runtime/core/utils/utils.cc index 86ba669..885f817 100644 --- a/runtime/core/utils/utils.cc +++ b/runtime/core/utils/utils.cc @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include +#include + +#include "utils/log.h" #include "utils/utils.h" namespace wetts { diff --git a/runtime/core/utils/utils.h b/runtime/core/utils/utils.h index 4b7f406..a667590 100644 --- a/runtime/core/utils/utils.h +++ b/runtime/core/utils/utils.h @@ -21,8 +21,6 @@ #include #include -#include "glog/logging.h" - #include "utils/string.h" namespace wetts {