Support WebAssembly for text-to-speech (#577)
This commit is contained in:
@@ -12,4 +12,3 @@ install(TARGETS sherpa-onnx-c-api DESTINATION lib)
|
||||
install(FILES c-api.h
|
||||
DESTINATION include/sherpa-onnx/c-api
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "sherpa-onnx/csrc/circular-buffer.h"
|
||||
#include "sherpa-onnx/csrc/display.h"
|
||||
#include "sherpa-onnx/csrc/macros.h"
|
||||
#include "sherpa-onnx/csrc/offline-recognizer.h"
|
||||
#include "sherpa-onnx/csrc/offline-tts.h"
|
||||
#include "sherpa-onnx/csrc/online-recognizer.h"
|
||||
@@ -90,7 +91,7 @@ SherpaOnnxOnlineRecognizer *CreateOnlineRecognizer(
|
||||
SHERPA_ONNX_OR(config->hotwords_score, 1.5);
|
||||
|
||||
if (config->model_config.debug) {
|
||||
fprintf(stderr, "%s\n", recognizer_config.ToString().c_str());
|
||||
SHERPA_ONNX_LOGE("%s\n", recognizer_config.ToString().c_str());
|
||||
}
|
||||
|
||||
SherpaOnnxOnlineRecognizer *recognizer = new SherpaOnnxOnlineRecognizer;
|
||||
@@ -320,7 +321,7 @@ SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer(
|
||||
SHERPA_ONNX_OR(config->hotwords_score, 1.5);
|
||||
|
||||
if (config->model_config.debug) {
|
||||
fprintf(stderr, "%s\n", recognizer_config.ToString().c_str());
|
||||
SHERPA_ONNX_LOGE("%s", recognizer_config.ToString().c_str());
|
||||
}
|
||||
|
||||
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer;
|
||||
@@ -476,7 +477,7 @@ SherpaOnnxVoiceActivityDetector *SherpaOnnxCreateVoiceActivityDetector(
|
||||
vad_config.debug = SHERPA_ONNX_OR(config->debug, false);
|
||||
|
||||
if (vad_config.debug) {
|
||||
fprintf(stderr, "%s\n", vad_config.ToString().c_str());
|
||||
SHERPA_ONNX_LOGE("%s", vad_config.ToString().c_str());
|
||||
}
|
||||
|
||||
SherpaOnnxVoiceActivityDetector *p = new SherpaOnnxVoiceActivityDetector;
|
||||
@@ -566,7 +567,7 @@ SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTts(
|
||||
tts_config.max_num_sentences = SHERPA_ONNX_OR(config->max_num_sentences, 2);
|
||||
|
||||
if (tts_config.model.debug) {
|
||||
fprintf(stderr, "%s\n", tts_config.ToString().c_str());
|
||||
SHERPA_ONNX_LOGE("%s\n", tts_config.ToString().c_str());
|
||||
}
|
||||
|
||||
SherpaOnnxOfflineTts *tts = new SherpaOnnxOfflineTts;
|
||||
@@ -582,6 +583,10 @@ int32_t SherpaOnnxOfflineTtsSampleRate(const SherpaOnnxOfflineTts *tts) {
|
||||
return tts->impl->SampleRate();
|
||||
}
|
||||
|
||||
int32_t SherpaOnnxOfflineTtsNumSpeakers(const SherpaOnnxOfflineTts *tts) {
|
||||
return tts->impl->NumSpeakers();
|
||||
}
|
||||
|
||||
const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate(
|
||||
const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
|
||||
float speed) {
|
||||
|
||||
@@ -658,6 +658,10 @@ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTts(SherpaOnnxOfflineTts *tts);
|
||||
SHERPA_ONNX_API int32_t
|
||||
SherpaOnnxOfflineTtsSampleRate(const SherpaOnnxOfflineTts *tts);
|
||||
|
||||
// Return the number of speakers of the current TTS object
|
||||
SHERPA_ONNX_API int32_t
|
||||
SherpaOnnxOfflineTtsNumSpeakers(const SherpaOnnxOfflineTts *tts);
|
||||
|
||||
// Generate audio from the given text and speaker id (sid).
|
||||
// The user has to use DestroyOfflineTtsGeneratedAudio() to free the
|
||||
// returned pointer to avoid memory leak.
|
||||
|
||||
@@ -128,9 +128,6 @@ if(APPLE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(sherpa-onnx-core -pthread)
|
||||
endif()
|
||||
|
||||
if(ANDROID_NDK)
|
||||
target_link_libraries(sherpa-onnx-core android log)
|
||||
@@ -172,36 +169,42 @@ if(SHERPA_ONNX_ENABLE_CHECK)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||
target_link_libraries(sherpa-onnx-core -pthread -ldl)
|
||||
target_link_libraries(sherpa-onnx-core -ldl)
|
||||
endif()
|
||||
|
||||
add_executable(sherpa-onnx sherpa-onnx.cc)
|
||||
add_executable(sherpa-onnx-keyword-spotter sherpa-onnx-keyword-spotter.cc)
|
||||
add_executable(sherpa-onnx-offline sherpa-onnx-offline.cc)
|
||||
add_executable(sherpa-onnx-offline-parallel sherpa-onnx-offline-parallel.cc)
|
||||
add_executable(sherpa-onnx-offline-tts sherpa-onnx-offline-tts.cc)
|
||||
if(NOT WIN32 AND NOT SHERPA_ONNX_ENABLE_WASM AND CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||
target_link_libraries(sherpa-onnx-core -pthread)
|
||||
endif()
|
||||
|
||||
set(main_exes
|
||||
sherpa-onnx
|
||||
sherpa-onnx-keyword-spotter
|
||||
sherpa-onnx-offline
|
||||
sherpa-onnx-offline-parallel
|
||||
sherpa-onnx-offline-tts
|
||||
)
|
||||
if(SHERPA_ONNX_ENABLE_BINARY)
|
||||
add_executable(sherpa-onnx sherpa-onnx.cc)
|
||||
add_executable(sherpa-onnx-keyword-spotter sherpa-onnx-keyword-spotter.cc)
|
||||
add_executable(sherpa-onnx-offline sherpa-onnx-offline.cc)
|
||||
add_executable(sherpa-onnx-offline-parallel sherpa-onnx-offline-parallel.cc)
|
||||
add_executable(sherpa-onnx-offline-tts sherpa-onnx-offline-tts.cc)
|
||||
|
||||
foreach(exe IN LISTS main_exes)
|
||||
target_link_libraries(${exe} sherpa-onnx-core)
|
||||
endforeach()
|
||||
set(main_exes
|
||||
sherpa-onnx
|
||||
sherpa-onnx-keyword-spotter
|
||||
sherpa-onnx-offline
|
||||
sherpa-onnx-offline-parallel
|
||||
sherpa-onnx-offline-tts
|
||||
)
|
||||
|
||||
if(NOT WIN32)
|
||||
foreach(exe IN LISTS main_exes)
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../lib")
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../../../sherpa_onnx/lib")
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_PYTHON)
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../lib/python${PYTHON_VERSION}/site-packages/sherpa_onnx/lib")
|
||||
endif()
|
||||
target_link_libraries(${exe} sherpa-onnx-core)
|
||||
endforeach()
|
||||
|
||||
if(NOT WIN32)
|
||||
foreach(exe IN LISTS main_exes)
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../lib")
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../../../sherpa_onnx/lib")
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_PYTHON)
|
||||
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_ONNX_RPATH_ORIGIN}/../lib/python${PYTHON_VERSION}/site-packages/sherpa_onnx/lib")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32)
|
||||
@@ -214,14 +217,16 @@ if(WIN32 AND BUILD_SHARED_LIBS)
|
||||
install(TARGETS sherpa-onnx-core DESTINATION bin)
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
${main_exes}
|
||||
DESTINATION
|
||||
bin
|
||||
)
|
||||
if(SHERPA_ONNX_ENABLE_BINARY)
|
||||
install(
|
||||
TARGETS
|
||||
${main_exes}
|
||||
DESTINATION
|
||||
bin
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SHERPA_ONNX_HAS_ALSA)
|
||||
if(SHERPA_ONNX_HAS_ALSA AND SHERPA_ONNX_ENABLE_BINARY)
|
||||
add_executable(sherpa-onnx-alsa sherpa-onnx-alsa.cc alsa.cc)
|
||||
add_executable(sherpa-onnx-offline-tts-play-alsa sherpa-onnx-offline-tts-play-alsa.cc alsa-play.cc)
|
||||
|
||||
@@ -261,7 +266,7 @@ if(SHERPA_ONNX_HAS_ALSA)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_PORTAUDIO)
|
||||
if(SHERPA_ONNX_ENABLE_PORTAUDIO AND SHERPA_ONNX_ENABLE_BINARY)
|
||||
add_executable(sherpa-onnx-offline-tts-play
|
||||
sherpa-onnx-offline-tts-play.cc
|
||||
microphone.cc
|
||||
@@ -330,7 +335,7 @@ if(SHERPA_ONNX_ENABLE_PORTAUDIO)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_WEBSOCKET)
|
||||
if(SHERPA_ONNX_ENABLE_WEBSOCKET AND SHERPA_ONNX_ENABLE_BINARY)
|
||||
add_definitions(-DASIO_STANDALONE)
|
||||
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
|
||||
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
fprintf(stderr, "\n"); \
|
||||
__android_log_print(ANDROID_LOG_WARN, "sherpa-onnx", ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#elif SHERPA_ONNX_ENABLE_WASM
|
||||
#define SHERPA_ONNX_LOGE(...) \
|
||||
do { \
|
||||
fprintf(stdout, "%s:%s:%d ", __FILE__, __func__, \
|
||||
static_cast<int>(__LINE__)); \
|
||||
fprintf(stdout, ##__VA_ARGS__); \
|
||||
fprintf(stdout, "\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define SHERPA_ONNX_LOGE(...) \
|
||||
do { \
|
||||
|
||||
Reference in New Issue
Block a user