-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from VOICEVOX/cpp-library
C++ TTSライブラリを`main`にマージ
- Loading branch information
Showing
21 changed files
with
1,726 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "open_jtalk"] | ||
path = open_jtalk | ||
url = https://github.com/VOICEVOX/open_jtalk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <cstdlib> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
#include "core.h" | ||
#include "engine/kana_parser.h" | ||
#include "engine/model.h" | ||
#include "engine/synthesis_engine.h" | ||
|
||
using namespace voicevox::core::engine; | ||
|
||
static SynthesisEngine engine; | ||
|
||
VoicevoxResultCode voicevox_load_openjtalk_dict(const char *dict_path) { | ||
// TODO: error handling | ||
engine.load_openjtalk_dict(dict_path); | ||
return VOICEVOX_RESULT_SUCCEED; | ||
} | ||
|
||
VoicevoxResultCode voicevox_tts(const char *text, int64_t speaker_id, int *output_binary_size, uint8_t **output_wav) { | ||
if (!engine.is_openjtalk_dict_loaded()) { | ||
return VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT; | ||
} | ||
|
||
std::vector<AccentPhraseModel> accent_phrases = engine.create_accent_phrases(std::string(text), &speaker_id); | ||
const AudioQueryModel audio_query = { | ||
accent_phrases, 1.0f, 0.0f, 1.0f, 1.0f, 0.1f, 0.1f, engine.default_sampling_rate, false, "", | ||
}; | ||
|
||
const auto wav = engine.synthesis_wave_format(audio_query, &speaker_id, output_binary_size); | ||
auto *wav_heap = new uint8_t[*output_binary_size]; | ||
std::copy(wav.begin(), wav.end(), wav_heap); | ||
*output_wav = wav_heap; | ||
return VOICEVOX_RESULT_SUCCEED; | ||
} | ||
|
||
VoicevoxResultCode voicevox_tts_from_kana(const char *text, int64_t speaker_id, int *output_binary_size, | ||
uint8_t **output_wav) { | ||
std::vector<AccentPhraseModel> accent_phrases = parse_kana(std::string(text)); | ||
accent_phrases = engine.replace_mora_data(accent_phrases, &speaker_id); | ||
const AudioQueryModel audio_query = { | ||
accent_phrases, 1.0f, 0.0f, 1.0f, 1.0f, 0.1f, 0.1f, engine.default_sampling_rate, false, "", | ||
}; | ||
|
||
const auto wav = engine.synthesis_wave_format(audio_query, &speaker_id, output_binary_size); | ||
auto *wav_heap = new uint8_t[*output_binary_size]; | ||
std::copy(wav.begin(), wav.end(), wav_heap); | ||
*output_wav = wav_heap; | ||
return VOICEVOX_RESULT_SUCCEED; | ||
} | ||
|
||
void voicevox_wav_free(uint8_t *wav) { delete wav; } | ||
|
||
const char *voicevox_error_result_to_message(VoicevoxResultCode result_code) { | ||
switch (result_code) { | ||
case VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT: | ||
return "Call voicevox_load_openjtalk_dict() first."; | ||
|
||
default: | ||
throw std::runtime_error("Unexpected error result code."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "acoustic_feature_extractor.h" | ||
|
||
namespace voicevox::core::engine { | ||
long OjtPhoneme::phoneme_id() const { | ||
if (phoneme.empty()) return (long)-1; | ||
return (long)phoneme_map().at(phoneme); | ||
} | ||
|
||
std::vector<OjtPhoneme> OjtPhoneme::convert(std::vector<OjtPhoneme> phonemes) { | ||
if (phonemes[0].phoneme.find("sil") != std::string::npos) { | ||
phonemes[0].phoneme = OjtPhoneme::space_phoneme(); | ||
} | ||
if (phonemes.back().phoneme.find("sil") != std::string::npos) { | ||
phonemes.back().phoneme = OjtPhoneme::space_phoneme(); | ||
} | ||
return phonemes; | ||
} | ||
} // namespace voicevox::core::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace voicevox::core::engine { | ||
// TODO: 現状のVOICEVOX/voiceovox_engineではOjtしか使われていないので、一旦これのみ実装した | ||
class OjtPhoneme { | ||
public: | ||
std::string phoneme; | ||
float start; | ||
float end; | ||
|
||
static const std::map<std::string, int> phoneme_map() { | ||
std::map<std::string, int> phoneme_map = { | ||
{"pau", 0}, {"A", 1}, {"E", 2}, {"I", 3}, {"N", 4}, {"O", 5}, {"U", 6}, {"a", 7}, {"b", 8}, | ||
{"by", 9}, {"ch", 10}, {"cl", 11}, {"d", 12}, {"dy", 13}, {"e", 14}, {"f", 15}, {"g", 16}, {"gw", 17}, | ||
{"gy", 18}, {"h", 19}, {"hy", 20}, {"i", 21}, {"j", 22}, {"k", 23}, {"kw", 24}, {"ky", 25}, {"m", 26}, | ||
{"my", 27}, {"n", 28}, {"ny", 29}, {"o", 30}, {"p", 31}, {"py", 32}, {"r", 33}, {"ry", 34}, {"s", 35}, | ||
{"sh", 36}, {"t", 37}, {"ts", 38}, {"ty", 39}, {"u", 40}, {"v", 41}, {"w", 42}, {"y", 43}, {"z", 44}}; | ||
return phoneme_map; | ||
} | ||
static int num_phoneme() { return (int)phoneme_map().size(); } | ||
static const std::string space_phoneme() { return std::string("pau"); } | ||
|
||
OjtPhoneme() { | ||
phoneme = ""; | ||
start = 0.0; | ||
end = 0.0; | ||
} | ||
|
||
OjtPhoneme(std::string c_phoneme, float c_start, float c_end) { | ||
phoneme = c_phoneme; | ||
start = c_start; | ||
end = c_end; | ||
} | ||
|
||
long phoneme_id() const; | ||
static std::vector<OjtPhoneme> convert(std::vector<OjtPhoneme> phonemes); | ||
}; | ||
} // namespace voicevox::core::engine |
Oops, something went wrong.