Skip to content

Commit

Permalink
Added offline-tts-cache-mechanism-config.cc,.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 24, 2025
1 parent f0c5242 commit f6e11ed
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions sherpa-onnx/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ if(SHERPA_ONNX_ENABLE_TTS)
jieba-lexicon.cc
lexicon.cc
melo-tts-lexicon.cc
offline-tts-cache-mechanism-config.cc
offline-tts-cache-mechanism.cc
offline-tts-character-frontend.cc
offline-tts-frontend.cc
Expand Down
35 changes: 35 additions & 0 deletions sherpa-onnx/csrc/offline-tts-cache-mechanism-config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// sherpa-onnx/csrc/offline-tts-cache-mechanism-config.cc
//
// Copyright (c) 2025 @mah92 From Iranian people to the community with love

#include "sherpa-onnx/csrc/offline-tts-cache-mechanism-config.h"

#include <vector>

#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"

namespace sherpa_onnx {

void OfflineTtsCacheMechanismConfig::Register(ParseOptions *po) {
po->Register("tts-cache-dir", &cache_dir,
"Path to the directory containing dict for espeak-ng.");
po->Register("tts-cache-size", &cache_size,
"Cache size for wav files in bytes. After the cache size is filled, wav files are kept based on usage statstics.");
}

bool OfflineTtsCacheMechanismConfig::Validate() const {
return true;
}

std::string OfflineTtsCacheMechanismConfig::ToString() const {
std::ostringstream os;

os << "OfflineTtsCacheMechanismConfig(";
os << "cache_dir=\"" << cache_dir << "\", ";
os << "cache_size=" << cache_size << ")";

return os.str();
}

} // namespace sherpa_onnx
35 changes: 35 additions & 0 deletions sherpa-onnx/csrc/offline-tts-cache-mechanism-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// sherpa-onnx/csrc/offline-tts-cache-mechanism-config.h
//
// Copyright (c) 2025 @mah92 From Iranian people to the community with love

#ifndef SHERPA_ONNX_CSRC_OFFLINE_TTS_CACHE_MECHANISM_CONFIG_H_
#define SHERPA_ONNX_CSRC_OFFLINE_TTS_CACHE_MECHANISM_CONFIG_H_

#include <string>

#include "sherpa-onnx/csrc/parse-options.h"

namespace sherpa_onnx {

struct OfflineTtsCacheMechanismConfig {

std::string cache_dir;

int32_t cache_size;

OfflineTtsCacheMechanismConfig() = default;

OfflineTtsCacheMechanismConfig(const std::string &cache_dir,
int32_t cache_size)
: cache_dir(cache_dir),
cache_size(cache_size) {}

void Register(ParseOptions *po);
bool Validate() const;

std::string ToString() const;
};

} // namespace sherpa_onnx

#endif // SHERPA_ONNX_CSRC_OFFLINE_TTS_CACHE_MECHANISM_CONFIG_H_
2 changes: 2 additions & 0 deletions sherpa-onnx/csrc/offline-tts-cache-mechanism.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <unordered_map>
#include <mutex> // NOLINT

#include "sherpa-onnx/csrc/offline-tts-cache-mechanism-config.h"

namespace sherpa_onnx {

class OfflineTtsCacheMechanism {
Expand Down
2 changes: 1 addition & 1 deletion sherpa-onnx/csrc/offline-tts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/offline-tts-cache-mechanism.h"
#include "sherpa-onnx/csrc/offline-tts-impl.h"
#include "sherpa-onnx/csrc/text-utils.h"
#include "sherpa-onnx/csrc/offline-tts-cache-mechanism.h"

namespace sherpa_onnx {

Expand Down

0 comments on commit f6e11ed

Please sign in to comment.