Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions runtime/core/bin/http_server_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

#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
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/bin/tts_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <vector>

#include "gflags/gflags.h"
#include "glog/logging.h"
#include "utils/log.h"
#include "processor/wetext_processor.h"

#include "frontend/g2p_en.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/g2p_en.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/fst.h"
#include "utils/string.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/g2p_prosody.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <utility>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"
#include "utils/utils.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/lexicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <utility>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/sandhi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/sentence_break.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <unordered_set>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/wav.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <string>

#include "glog/logging.h"
#include "utils/log.h"

namespace wetts {

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/frontend/word_break.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <unordered_set>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

namespace wetts {

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/model/onnx_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "model/onnx_model.h"

#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"

Expand Down
2 changes: 1 addition & 1 deletion runtime/core/model/tts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <utility>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

#include "frontend/sentence_break.h"
#include "utils/string.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/model/vits_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <utility>
#include <vector>

#include "glog/logging.h"
#include "utils/log.h"

namespace wetts {

Expand Down
8 changes: 7 additions & 1 deletion runtime/core/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion runtime/core/utils/fst.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <vector>

#include "fst/fstlib.h"
#include "glog/logging.h"
#include "utils/log.h"

#include "utils/string.h"

Expand Down
147 changes: 147 additions & 0 deletions runtime/core/utils/log.h
Original file line number Diff line number Diff line change
@@ -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 <android/log.h>
#include <sstream>
#include <string>

// 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_
5 changes: 5 additions & 0 deletions runtime/core/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <unordered_map>
#include <vector>

#include "utils/log.h"
#include "utils/utils.h"

namespace wetts {
Expand Down
2 changes: 0 additions & 2 deletions runtime/core/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <utility>
#include <vector>

#include "glog/logging.h"

#include "utils/string.h"

namespace wetts {
Expand Down