diff --git a/.cspell-wordlist.txt b/.cspell-wordlist.txt index 3c17403a49..defed32659 100644 --- a/.cspell-wordlist.txt +++ b/.cspell-wordlist.txt @@ -7,6 +7,7 @@ RNET libexecutorch libxnnpack libvulkan +verbalis xcframework metallib ASPP diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b46ab8cf9..3404c4fdf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -186,7 +186,7 @@ jobs: - name: Check out the submodules the tests build run: | git submodule update --init --depth 1 third-party/googletest - GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --depth 1 \ + GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --recursive --depth 1 \ packages/react-native-executorch/third-party/common/phonemis working-directory: ${{ github.workspace }} @@ -287,6 +287,13 @@ jobs: - name: Checkout uses: actions/checkout@v6 + # The podspec suites evaluate the podspec, which requires phonemis' + # phonemis_sources.rb. Nothing reads phonemis' Git LFS `data/`. + - name: Check out phonemis + run: | + GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --depth 1 \ + packages/react-native-executorch/third-party/common/phonemis + - name: Setup uses: ./.github/actions/setup diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 2a6143ac51..069defd1f0 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -23,11 +23,15 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 - with: - # The phonemis submodule carries headers that cpp/extensions/speech - # includes; without it those sources fail to parse and clang-tidy - # reports misleading findings on the broken AST. - submodules: true + + # cpp/extensions/speech includes phonemis' headers, and through them + # Verbalis'; without them those sources fail to parse and clang-tidy + # reports misleading findings on the broken AST. phonemis' `data/` is + # Git LFS that nothing here reads, so the checkout skips it. + - name: Check out phonemis + run: | + GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --recursive --depth 1 \ + packages/react-native-executorch/third-party/common/phonemis - name: Setup uses: ./.github/actions/setup diff --git a/.gitmodules b/.gitmodules index 6236aeac75..3cdc51a302 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,5 +3,5 @@ url = https://github.com/google/googletest.git [submodule "packages/react-native-executorch/third-party/common/phonemis"] path = packages/react-native-executorch/third-party/common/phonemis - url = https://github.com/IgorSwat/Phonemis + url = https://github.com/software-mansion-labs/Phonemis branch = main diff --git a/LICENSE b/LICENSE index aa15d47034..7cbd9676d2 100644 --- a/LICENSE +++ b/LICENSE @@ -32,13 +32,17 @@ its own license, reproduced in full further down this file. OpenCV Apache-2.0 vision pipelines and multimodal LLMs KleidiCV Apache-2.0 OpenCV Arm HAL, Android only phonemis MIT grapheme-to-phoneme for text-to-speech + Verbalis MIT text preprocessing for phonemis MLX MIT MLX backend, iOS only Which of these end up in an application binary depends on the backends and libraries it enables; see the Native Libraries documentation. ExecuTorch in turn bundles further components, among them XNNPACK, pthreadpool, cpuinfo, the tokenizers library and PCRE2, each under its own permissive license and -covered by the notices shipped with the ExecuTorch distribution. +covered by the notices shipped with the ExecuTorch distribution. Likewise, +Verbalis bundles a port of cn2an (MIT) for Chinese numbers, and phonemis and +Verbalis list their own components in the THIRD_PARTY_NOTICES.md files under +third-party/common/phonemis. =============================================================================== @@ -107,6 +111,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +=============================================================================== +Verbalis, MIT +=============================================================================== + +Copyright (c) 2026 Software Mansion + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + =============================================================================== MLX, MIT =============================================================================== diff --git a/packages/react-native-executorch/compile_flags.txt b/packages/react-native-executorch/compile_flags.txt index 02a120dc77..ca161d47eb 100644 --- a/packages/react-native-executorch/compile_flags.txt +++ b/packages/react-native-executorch/compile_flags.txt @@ -5,6 +5,7 @@ -isystem../../node_modules/react-native/ReactCommon/jsi -isystemthird-party/include -isystemthird-party/common/phonemis/src +-isystemthird-party/common/phonemis/third-party/verbalis/cpp/include -isystemthird-party/include/executorch/extension/llm/tokenizers/include -isystemthird-party/include/executorch/extension/llm/tokenizers/third-party/json/include -isystemthird-party/include/executorch/extension/llm/tokenizers/third-party/re2 diff --git a/packages/react-native-executorch/cpp/tests/CMakeLists.txt b/packages/react-native-executorch/cpp/tests/CMakeLists.txt index f25fa07ec2..36cbcd6b29 100644 --- a/packages/react-native-executorch/cpp/tests/CMakeLists.txt +++ b/packages/react-native-executorch/cpp/tests/CMakeLists.txt @@ -227,18 +227,6 @@ endif() if(RNE_TESTS_ENABLE_PHONEMIS) add_subdirectory("${PHONEMIS_DIR}" "${CMAKE_BINARY_DIR}/phonemis" EXCLUDE_FROM_ALL) list(APPEND RNE_SOURCES ${PHONEMIS_SOURCES}) - - # Two phonemis headers use std::optional and std::u32string without including - # / . libc++ pulls both in transitively, so the Android - # (NDK) and iOS builds never notice; libstdc++ does not, and the member - # declarations then fail to parse, leaving a pile of "no declaration matches" - # errors on their definitions. Force-include the two headers rather than patch - # a pinned submodule; drop this once upstream adds the includes. - # SHELL: keeps the two -include flags paired; without it CMake de-duplicates - # the repeated -include and the second header becomes an input file. - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - target_compile_options(phonemis PRIVATE "SHELL:-include optional" "SHELL:-include string") - endif() endif() add_library(rne_under_test STATIC ${RNE_SOURCES}) @@ -296,7 +284,7 @@ if(RNE_TESTS_ENABLE_OPENCV) endif() # --- Test support ----------------------------------------------------------- -add_library(rne_test_support STATIC support/JsiTestEnv.cpp) +add_library(rne_test_support STATIC support/JsiTestEnv.cpp support/Snapshots.cpp) target_link_libraries(rne_test_support PUBLIC rne_under_test gtest gmock) target_include_directories(rne_test_support PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") @@ -306,6 +294,11 @@ target_include_directories(rne_test_support PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" target_compile_definitions(rne_test_support PUBLIC RNE_ERROR_TS_SOURCE="${PACKAGE_DIR}/src/core/error.ts") +# Snapshots of what third-party code produces, committed and updated with +# RNE_UPDATE_SNAPSHOTS=1 (support/Snapshots.h). +target_compile_definitions(rne_test_support PUBLIC + RNE_SNAPSHOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}/snapshots") + # --- Model fixture ---------------------------------------------------------- # Suites that read ExecuTorch MethodMeta need a real .pte. It is downloaded # rather than committed (scripts/fetch-test-fixtures.sh), so the suites that @@ -337,6 +330,25 @@ else() " scripts/fetch-test-fixtures.sh") endif() +# With Kokoro's tagger, segmenter and lexicons, phonemis produces real +# phonemes, so what it outputs can be pinned, not only how it is called. Same +# story again. +set(PHONEMIZER_FIXTURE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/fixtures/phonemizer") +set(RNE_HAVE_PHONEMIZER_FIXTURE ${RNE_TESTS_ENABLE_PHONEMIS}) +foreach(file en-us/tags.json en-us/lexicon.json en-gb/lexicon.json zh/segmenter.json zh/lexicon.json) + if(NOT EXISTS "${PHONEMIZER_FIXTURE_DIR}/${file}") + set(RNE_HAVE_PHONEMIZER_FIXTURE OFF) + endif() +endforeach() +if(RNE_HAVE_PHONEMIZER_FIXTURE) + target_compile_definitions(rne_test_support PUBLIC + RNE_PHONEMIZER_FIXTURE_DIR="${PHONEMIZER_FIXTURE_DIR}") +elseif(RNE_TESTS_ENABLE_PHONEMIS) + message(WARNING + "Phonemizer fixtures missing, skipping the PhonemizerOutputTest suite. Fetch them with:\n" + " scripts/fetch-test-fixtures.sh") +endif() + # --- Test binaries ---------------------------------------------------------- enable_testing() include(GoogleTest) @@ -359,7 +371,7 @@ if(RNE_TESTS_ENABLE_OPENCV) endif() if(RNE_TESTS_ENABLE_PHONEMIS) - list(APPEND TEST_SUITES extensions/PhonemizerTest.cpp) + list(APPEND TEST_SUITES extensions/PhonemizerTest.cpp extensions/PreprocessingTest.cpp) endif() if(RNE_HAVE_MODEL_FIXTURE) @@ -370,6 +382,10 @@ if(RNE_HAVE_TOKENIZER_FIXTURE) list(APPEND TEST_SUITES extensions/TokenizerTest.cpp) endif() +if(RNE_HAVE_PHONEMIZER_FIXTURE) + list(APPEND TEST_SUITES extensions/PhonemizerOutputTest.cpp) +endif() + foreach(suite_path IN LISTS TEST_SUITES) get_filename_component(suite_name "${suite_path}" NAME_WE) add_executable(${suite_name} "${suite_path}") diff --git a/packages/react-native-executorch/cpp/tests/README.md b/packages/react-native-executorch/cpp/tests/README.md index a694639e93..10416c19a5 100644 --- a/packages/react-native-executorch/cpp/tests/README.md +++ b/packages/react-native-executorch/cpp/tests/README.md @@ -45,7 +45,8 @@ rather than a lookalike. | `support/JsiTestEnv.*` | Fixture owning a Hermes runtime with the module installed, plus `eval*` helpers and the `isCodedError` / `throwsCoded` assertions | | `core/` | `dtype`, `error`, `conversions`, `tensor`, `schema`, `model`, `utils` | | `extensions/` | `math`, `speech`, `nlp` (tokenizer), `llm`, and — behind OpenCV — `cv` and `ocr` ops; `phonemizer` behind phonemis | -| `fixtures/` | Downloaded `.pte` program and `tokenizer.json` (gitignored) | +| `fixtures/` | Downloaded `.pte` program, `tokenizer.json` and phonemizer data (gitignored) | +| `snapshots/` | Committed outputs of phonemis, see below | One binary per suite, so a crash in one area cannot take the run down with it and `ctest -R MathOpsTest` targets a single suite. @@ -62,7 +63,7 @@ RNET_HEADERS_ONLY=1 node scripts/download-libs.js # 2. The submodules the tests compile. phonemis' `data/` is Git LFS and nothing # here reads it, so the checkout skips it. git submodule update --init --depth 1 ../../third-party/googletest -GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --depth 1 third-party/common/phonemis +GIT_LFS_SKIP_SMUDGE=1 git submodule update --init --recursive --depth 1 third-party/common/phonemis # 3. Hermes + a minimal ExecuTorch host build (several minutes, cached afterwards) scripts/build-native-test-deps.sh @@ -113,7 +114,7 @@ CMake package when present and otherwise locates the two libraries directly. ## The fixtures -`scripts/fetch-test-fixtures.sh` downloads two, both pinned to an exact Hugging +`scripts/fetch-test-fixtures.sh` downloads them, all pinned to an exact Hugging Face revision and checksum-verified. `run-native-tests.sh` fetches them automatically; they land in `fixtures/` and are gitignored rather than committed. @@ -121,6 +122,26 @@ automatically; they land in `fixtures/` and are gitignored rather than committed publishes. Anything reading ExecuTorch `MethodMeta` needs a real program. - A **tokenizer.json** — Whisper tiny.en's, ~2.4 MB. A plain BPE vocabulary, so the nlp extension's encode/decode path runs for real. +- Kokoro's **phonemizer data** for en-us, en-gb and zh, the tagger, segmenter + and lexicons the app ships, ~26 MB together. `PhonemizerOutputTest` runs + phonemis on them. The other languages need a neural model, so + `PreprocessingTest` covers only the text phonemis feeds it. + +## Snapshots + +What phonemis reads a text as changes with every phonemis or Verbalis bump, so +those readings are not hard-coded in the tests. `snapshots/*.txt` lists the +inputs and their committed outputs; a bump that changes one fails +`MatchesTheSnapshot` with the old and new value. Accept the change and review +the diff in the PR: + +```bash +RNE_UPDATE_SNAPSHOTS=1 scripts/run-native-tests.sh -R 'PhonemizerOutput|Preprocessing' +``` + +To add a case, add its ` | ` line and run the same command. The +`LeavesNoDigitsOrSymbols` and `LocatesEveryWordOfTheInput` checks hold across +versions and have no snapshot: a failure there is a real regression. The useful part is that this needs **no XNNPACK delegate**, even though the fixture is XNNPACK-delegated. `ModelHostObject`'s constructor only calls diff --git a/packages/react-native-executorch/cpp/tests/extensions/PhonemizerOutputTest.cpp b/packages/react-native-executorch/cpp/tests/extensions/PhonemizerOutputTest.cpp new file mode 100644 index 0000000000..a036cedb31 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/extensions/PhonemizerOutputTest.cpp @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include + +#include +#include + +#include "support/JsiTestEnv.h" +#include "support/Snapshots.h" + +namespace rnexecutorch::tests { +namespace { + +using PhonemizerOutputTest = JsiTestEnv; +using phonemis::utils::conversions::u32_to_utf8; +using phonemis::utils::conversions::utf8_to_u32; + +// PhonemizerTest pins the JSI contract with no phonemis data. These run the +// en-us, en-gb and zh pipelines on Kokoro's shipped tagger, segmenter and +// lexicons (scripts/fetch-test-fixtures.sh), so they pin what TTS is fed: the +// phonemes, and which of them each input word is located at, which is what +// word timings are built from. + +const std::string kSnapshot = std::string(RNE_SNAPSHOT_DIR) + "/phonemizer.txt"; + +// A pipeline's data, relative to RNE_PHONEMIZER_FIXTURE_DIR. en-gb's tagger is +// the same file as en-us's; zh's tagger slot holds its segmenter. +struct Data { + const char *tagger; + const char *lexicon; +}; + +const std::map kData = { + {"en-us", {"en-us/tags.json", "en-us/lexicon.json"}}, + {"en-gb", {"en-us/tags.json", "en-gb/lexicon.json"}}, + {"zh", {"zh/segmenter.json", "zh/lexicon.json"}}, +}; + +struct Phonemized { + std::string phonemes; + // Each located word as "text:phonemes", joined with '|'. + std::string words; + // What breaks the invariants of LocatesEveryWordOfTheInput, if anything. + std::string problems; +}; + +// `s` as a JS string literal. +std::string jsString(const std::string &s) { + std::string out = "'"; + for (char ch : s) { + if (ch == '\\' || ch == '\'') { + out += '\\'; + } + out += ch; + } + return out + "'"; +} + +// Phonemizes every text with one phonemizer, since loading the lexicon is what +// takes the time. +std::vector phonemize(JsiTestEnv &env, const std::string &lang, const std::vector &texts) { + auto data = kData.find(lang); + if (data == kData.end()) { + throw std::invalid_argument("no phonemizer data for " + lang); + } + std::string list; + for (const auto &text : texts) { + list += jsString(text) + ","; + } + // Each text as "phonemes\x1fwords\x1fproblems", separated by '\x1e'. + auto results = env.evalString(std::format(R"( + const p = __rnexecutorch_jsi__.speech.createPhonemizer({{ + lang: '{}', taggerSource: '{}/{}', lexiconSource: '{}/{}' }}); + return [{}].map((text) => {{ + const r = p.phonemize(text, {{ words: true }}); + const problems = []; + if (r.phonemes.length === 0) problems.push('no phonemes'); + if (r.words.length === 0) problems.push('no words located'); + let end = 0, phonemeEnd = 0; + for (const w of r.words) {{ + if (text.substr(w.offset, w.text.length) !== w.text) problems.push(`'${{w.text}}' is not at ${{w.offset}}`); + if (w.offset < end) problems.push(`'${{w.text}}' overlaps the word before`); + if (w.phonemeLength === 0) problems.push(`'${{w.text}}' has no phonemes`); + if (w.phonemeOffset < phonemeEnd) problems.push(`'${{w.text}}' phonemes overlap the word before`); + if (w.phonemeOffset + w.phonemeLength > r.phonemes.length) problems.push(`'${{w.text}}' phonemes run past the end`); + end = w.offset + w.text.length; + phonemeEnd = w.phonemeOffset + w.phonemeLength; + }} + for (let i = 0; i < text.length; ++i) {{ + if (/\s/.test(text[i])) continue; + if (!r.words.some((w) => w.offset <= i && i < w.offset + w.text.length)) {{ + problems.push(`'${{text[i]}}' at ${{i}} is in no word`); + break; + }} + }} + const words = r.words + .map((w) => w.text + ':' + r.phonemes.substr(w.phonemeOffset, w.phonemeLength)) + .join('|'); + return [r.phonemes, words, problems.join('; ')].join('\x1f'); + }}).join('\x1e'); + )", + lang, RNE_PHONEMIZER_FIXTURE_DIR, data->second.tagger, + RNE_PHONEMIZER_FIXTURE_DIR, data->second.lexicon, list)); + + std::vector out; + size_t begin = 0; + for (size_t i = 0; i < texts.size(); ++i) { + auto end = results.find('\x1e', begin); + auto record = results.substr(begin, end - begin); + auto first = record.find('\x1f'); + auto second = record.find('\x1f', first + 1); + out.push_back({record.substr(0, first), record.substr(first + 1, second - first - 1), + record.substr(second + 1)}); + begin = end == std::string::npos ? results.size() : end + 1; + } + return out; +} + +// Every case of the snapshot, phonemized, in order: one phonemizer per language. +std::vector phonemizeAll(JsiTestEnv &env, const std::vector &cases) { + std::map> byLang; + for (size_t i = 0; i < cases.size(); ++i) { + byLang[cases[i].lang].push_back(i); + } + std::vector out(cases.size()); + for (const auto &[lang, indices] : byLang) { + std::vector texts; + for (auto i : indices) { + texts.push_back(cases[i].input); + } + auto results = phonemize(env, lang, texts); + for (size_t j = 0; j < indices.size(); ++j) { + out[indices[j]] = std::move(results[j]); + } + } + return out; +} + +// Holds across versions: however a text is read, it has phonemes, and each of +// its words is located once, in order, at phonemes of its own. A phrase read +// as one unit ("3:30 pm") may come back as one word spanning several. +TEST_F(PhonemizerOutputTest, LocatesEveryWordOfTheInput) { + auto cases = snapshots::read(kSnapshot); + auto results = phonemizeAll(*this, cases); + for (size_t i = 0; i < cases.size(); ++i) { + EXPECT_EQ(results[i].problems, "") << "[" << cases[i].lang << "] " << cases[i].input; + } +} + +TEST_F(PhonemizerOutputTest, MatchesTheSnapshot) { + snapshots::verify(kSnapshot, [this](const std::vector &cases) { + auto results = phonemizeAll(*this, cases); + std::vector out; + for (size_t i = 0; i < cases.size(); ++i) { + phonemis::Pipeline pipeline(phonemis::Config{.lang = cases[i].lang}); + out.push_back({ + {"preprocessed", u32_to_utf8(pipeline.preprocess(utf8_to_u32(cases[i].input)))}, + {"phonemes", results[i].phonemes}, + {"words", results[i].words}, + }); + } + return out; + }); +} + +} // namespace +} // namespace rnexecutorch::tests diff --git a/packages/react-native-executorch/cpp/tests/extensions/PreprocessingTest.cpp b/packages/react-native-executorch/cpp/tests/extensions/PreprocessingTest.cpp new file mode 100644 index 0000000000..99c3a4ab69 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/extensions/PreprocessingTest.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include + +#include +#include + +#include "support/Snapshots.h" + +namespace rnexecutorch::tests { +namespace { + +using phonemis::utils::conversions::u32_to_utf8; +using phonemis::utils::conversions::utf8_to_u32; + +// Preprocessing (Verbalis, inside phonemis) reads numbers, dates, money, times +// and abbreviations out as words before anything is phonemized. It needs no +// data, so these go below the JSI layer, to phonemis directly, and cover every +// language: de, fr, es, it, pl, pt and hi are phonemized by a neural model that +// these tests cannot run, so for them this is all that is pinned. + +const std::string kSnapshot = std::string(RNE_SNAPSHOT_DIR) + "/preprocessing.txt"; + +std::string preprocess(const std::string &lang, const std::string &text) { + phonemis::Pipeline pipeline(phonemis::Config{.lang = lang}); + return u32_to_utf8(pipeline.preprocess(utf8_to_u32(text))); +} + +// Holds across versions: what a reading looks like may change, but nothing is +// left for the phonemizer to spell out character by character. +TEST(PreprocessingTest, LeavesNoDigitsOrSymbols) { + constexpr std::string_view kUnread[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "$", "€", "£", "₹", "%", "/", "º", "°"}; + for (const auto *file : {"/preprocessing.txt", "/phonemizer.txt"}) { + for (const auto &c : snapshots::read(std::string(RNE_SNAPSHOT_DIR) + file)) { + auto out = preprocess(c.lang, c.input); + for (auto unread : kUnread) { + EXPECT_EQ(out.find(unread), std::string::npos) + << "[" << c.lang << "] " << c.input << " => " << out << " still holds " << unread; + } + } + } +} + +TEST(PreprocessingTest, MatchesTheSnapshot) { + snapshots::verify(kSnapshot, [](const std::vector &cases) { + std::vector out; + for (const auto &c : cases) { + out.push_back({{"preprocessed", preprocess(c.lang, c.input)}}); + } + return out; + }); +} + +} // namespace +} // namespace rnexecutorch::tests diff --git a/packages/react-native-executorch/cpp/tests/snapshots/phonemizer.txt b/packages/react-native-executorch/cpp/tests/snapshots/phonemizer.txt new file mode 100644 index 0000000000..47a3c4f4d9 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/snapshots/phonemizer.txt @@ -0,0 +1,133 @@ +# What phonemis produces on Kokoro's shipped en-us, en-gb and zh data +# (PhonemizerOutputTest). Format and update command: support/Snapshots.h. +# The neural fallback isn't loaded, so inputs stick to words the lexicon knows. + +en-us | Hello world. + preprocessed: Hello world. + phonemes: həlˈO wˈɜɹld. + words: Hello:həlˈO|world.:wˈɜɹld. +en-us | I have 25 cats. + preprocessed: I have twenty-five cats. + phonemes: ˌI hæv twˈɛntifˈIv kˈæts. + words: I:ˌI|have:hæv|25:twˈɛntifˈIv|cats.:kˈæts. +en-us | It happened in 1999. + preprocessed: It happened in nineteen ninety-nine. + phonemes: ˌɪt hˈæpənd ɪn nˌIntˈin nˈIndinˈIn. + words: It:ˌɪt|happened:hˈæpənd|in:ɪn|1999.:nˌIntˈin nˈIndinˈIn. +en-us | The 21st century began. + preprocessed: The twenty-first century began. + phonemes: ðə twˈɛntifˈɜɹst sˈɛnʧəɹi bəɡˈæn. + words: The:ðə|21st:twˈɛntifˈɜɹst|century:sˈɛnʧəɹi|began.:bəɡˈæn. +en-us | Pi is roughly 3.14. + preprocessed: Pi is roughly three point one four. + phonemes: pˈI ɪz ɹˈʌfli θɹˈi pˈYnt wˈʌn fˈɔɹ. + words: Pi:pˈI|is:ɪz|roughly:ɹˈʌfli|3.14.:θɹˈi pˈYnt wˈʌn fˈɔɹ. +en-us | We sold 1,000,000 copies. + preprocessed: We sold one million copies. + phonemes: wˌi sˈOld wˈʌn mˈɪljᵊn kˈɑpiz. + words: We:wˌi|sold:sˈOld|1,000,000:wˈʌn mˈɪljᵊn|copies.:kˈɑpiz. +en-us | Chapter IV starts here. + preprocessed: Chapter four starts here. + phonemes: ʧˈæptəɹ fˈɔɹ stˈɑɹts hˈɪɹ. + words: Chapter:ʧˈæptəɹ|IV:fˈɔɹ|starts:stˈɑɹts|here.:hˈɪɹ. +en-us | Call 555-1234 now. + preprocessed: Call five five five, one two three four now. + phonemes: kˈɔl fˈIv fˈIv fˈIv, wˈʌn tˈu θɹˈi fˈɔɹ nˈW. + words: Call:kˈɔl|555-1234:fˈIv fˈIv fˈIv, wˈʌn tˈu θɹˈi fˈɔɹ|now.:nˈW. +en-us | It costs $4.50 today. + preprocessed: It costs four dollars and fifty cents today. + phonemes: ˌɪt kˈɔsts fˈɔɹ dˈɑləɹz ænd fˈɪfti sˈɛnts tədˈA. + words: It:ˌɪt|costs:kˈɔsts|$4.50:fˈɔɹ dˈɑləɹz ænd fˈɪfti sˈɛnts|today.:tədˈA. +en-us | About 50% of people agree. + preprocessed: About fifty percent of people agree. + phonemes: əbˈWt fˈɪfti pəɹsˈɛnt ʌv pˈipᵊl əɡɹˈi. + words: About:əbˈWt|50%:fˈɪfti pəɹsˈɛnt|of:ʌv|people:pˈipᵊl|agree.:əɡɹˈi. +en-us | On 12/25/2024 we left. + preprocessed: On December twenty-fifth twenty twenty-four we left. + phonemes: ˈɔn disˈɛmbəɹ twˈɛntifˈɪfθ twˈɛnti twˈɛntifˈɔɹ wi lˈɛft. + words: On:ˈɔn|12/25/2024:disˈɛmbəɹ twˈɛntifˈɪfθ twˈɛnti twˈɛntifˈɔɹ|we:wi|left.:lˈɛft. +en-us | Born on May 5, 2024. + preprocessed: Born on May fifth, twenty twenty-four. + phonemes: bˈɔɹn ˌɔn mˈA fˈɪfθ, twˈɛnti twˈɛntifˈɔɹ. + words: Born:bˈɔɹn|on:ˌɔn|May:mˈA|5,:fˈɪfθ,|2024.:twˈɛnti twˈɛntifˈɔɹ. +en-us | Dr. Smith lives on Main St. + preprocessed: Doctor Smith lives on Main Street. + phonemes: dˈɑktəɹ smˈɪθ lˈIvz ˌɔn mˈAn stɹˈit. + words: Dr.:dˈɑktəɹ|Smith:smˈɪθ|lives:lˈIvz|on:ˌɔn|Main:mˈAn|St.:stɹˈit. +en-us | Bring fruit, e.g. apples. + preprocessed: Bring fruit, for example apples. + phonemes: bɹˈɪŋ fɹˈut, fɔɹ ɪɡzˈæmpəl ˈæpᵊlz. + words: Bring:bɹˈɪŋ|fruit,:fɹˈut,|e.g.:fɔɹ ɪɡzˈæmpəl|apples.:ˈæpᵊlz. +en-us | Rock & roll. + preprocessed: Rock and roll. + phonemes: ɹˈɑk ænd ɹˈOl. + words: Rock:ɹˈɑk|&:ænd|roll.:ɹˈOl. +# A time or a measure is read as one phrase, so it is located as one word. +en-us | Meet me at 3:30 pm. + preprocessed: Meet me at three thirty p.m. + phonemes: mˈit mˌi æt θɹˈi θˈɜɹɾi pˈiˈɛm. + words: Meet:mˈit|me:mˌi|at:æt|3:30 pm.:θɹˈi θˈɜɹɾi pˈiˈɛm. +en-us | She ran 5 km. + preprocessed: She ran five kilometers. + phonemes: ʃˌi ɹˈæn fˈIv kəlˈɑməɾəɹz. + words: She:ʃˌi|ran:ɹˈæn|5 km.:fˈIv kəlˈɑməɾəɹz. + +en-gb | It costs £4.50 today. + preprocessed: It costs four pounds and fifty pence today. + phonemes: ˌɪt kˈɒsts fˈɔː pˈWndz and fˈɪfti pˈɛns tədˈA. + words: It:ˌɪt|costs:kˈɒsts|£4.50:fˈɔː pˈWndz and fˈɪfti pˈɛns|today.:tədˈA. +en-gb | On 24/12/2024 we left. + preprocessed: On the twenty-fourth of December twenty twenty-four we left. + phonemes: ˈɒn ðə twˈɛntifˈɔːθ ɒv dɪsˈɛmbə twˈɛnti twˈɛntifˈɔː wiː lˈɛft. + words: On:ˈɒn|24/12/2024:ðə twˈɛntifˈɔːθ ɒv dɪsˈɛmbə twˈɛnti twˈɛntifˈɔː|we:wiː|left.:lˈɛft. +en-gb | The 21st century. + preprocessed: The twenty-first century. + phonemes: ðə twˈɛntifˈɜːst sˈɛnʧʊɹi. + words: The:ðə|21st:twˈɛntifˈɜːst|century.:sˈɛnʧʊɹi. +en-gb | About 50% agree. + preprocessed: About fifty percent agree. + phonemes: əbˈWt fˈɪfti pəsˈɛnt əɡɹˈiː. + words: About:əbˈWt|50%:fˈɪfti pəsˈɛnt|agree.:əɡɹˈiː. +en-gb | Meet me at 3:30 pm. + preprocessed: Meet me at three thirty p.m. + phonemes: mˈiːt mˌiː at θɹˈiː θˈɜːti pˈiːˈɛm. + words: Meet:mˈiːt|me:mˌiː|at:at|3:30 pm.:θɹˈiː θˈɜːti pˈiːˈɛm. +en-gb | Dr. Smith ran 5 km. + preprocessed: Doctor Smith ran five kilometers. + phonemes: dˈɒktə smˈɪθ ɹˈan fˈIv kˈɪləmˌiːtəz. + words: Dr.:dˈɒktə|Smith:smˈɪθ|ran:ɹˈan|5 km.:fˈIv kˈɪləmˌiːtəz. +# Wrong: 946 should be read digit by digit (Verbalis#8). +en-gb | Call 0207 946 0018 now. + preprocessed: Call zero two zero seven nine hundred forty-six zero zero one eight now. + phonemes: kˈɔːl zˈɪəɹQ tˈuː zˈɪəɹQ sˈɛvᵊn nˈIn hˈʌndɹəd fˈɔːtisˈɪks zˈɪəɹQ zˈɪəɹQ wˈʌn ˈAt nˈW. + words: Call:kˈɔːl|0207:zˈɪəɹQ tˈuː zˈɪəɹQ sˈɛvᵊn|946:nˈIn hˈʌndɹəd fˈɔːtisˈɪks|0018:zˈɪəɹQ zˈɪəɹQ wˈʌn ˈAt|now.:nˈW. + +# zh segments the text into words, so a located word can span several characters. +zh | 我有25只猫。 + preprocessed: 我有二十五只猫. + phonemes: wo↓ jou↓ ɚ↘ʂɨ↗u↓ ꭧɨ↓ mau→. + words: 我:wo↓|有:jou↓|25:ɚ↘ʂɨ↗u↓|只:ꭧɨ↓|猫。:mau→. +zh | 价格是4.50元。 + preprocessed: 价格是四点五零元. + phonemes: ʨja↘kɤ↗ ʂɨ↘ sɨ↘tjɛ↓n u↓li↗ŋ ɥɛ↗n. + words: 价格:ʨja↘kɤ↗|是:ʂɨ↘|4.50:sɨ↘tjɛ↓n u↓li↗ŋ|元。:ɥɛ↗n. +zh | 2024年12月24日我们走了。 + preprocessed: 二零二四年十二月二十四日我们走了. + phonemes: ɚ↘li↗ŋɚ↘ sɨ↘njɛ↗n ʂɨ↗ɚ↘ɥe↘ ɚ↘ʂɨ↗sɨ↘ɻɨ↘ wo↓mən ʦou↓ lɤ. + words: 2024年12月24日:ɚ↘li↗ŋɚ↘ sɨ↘njɛ↗n ʂɨ↗ɚ↘ɥe↘ ɚ↘ʂɨ↗sɨ↘ɻɨ↘|我们:wo↓mən|走:ʦou↓|了。:lɤ. +zh | 下午3:30见。 + preprocessed: 下午三点三十分见. + phonemes: ɕja↘u↓ sa→ntjɛ↓n sa→nʂɨ↗fə→n ʨjɛ↘n. + words: 下午:ɕja↘u↓|3:30:sa→ntjɛ↓n sa→nʂɨ↗fə→n|见。:ʨjɛ↘n. +zh | 第3天。 + preprocessed: 第三天. + phonemes: ti↘sa→ntʰjɛ→n. + words: 第3天。:ti↘sa→ntʰjɛ→n. +zh | 大约50%的人同意。 + preprocessed: 大约百分之五十的人同意. + phonemes: ta↘ɥe→ pai↓fə→nꭧɨ→u↓ʂɨ↗ tɤ ɻə↗n tʰʊ↗ŋi↘. + words: 大约:ta↘ɥe→|50%:pai↓fə→nꭧɨ→u↓ʂɨ↗|的:tɤ|人:ɻə↗n|同意。:tʰʊ↗ŋi↘. +zh | 1999年。 + preprocessed: 一九九九年. + phonemes: i→ʨjou↓ʨjou↓ʨjou↓njɛ↗n. + words: 1999年。:i→ʨjou↓ʨjou↓ʨjou↓njɛ↗n. diff --git a/packages/react-native-executorch/cpp/tests/snapshots/preprocessing.txt b/packages/react-native-executorch/cpp/tests/snapshots/preprocessing.txt new file mode 100644 index 0000000000..433caa5e43 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/snapshots/preprocessing.txt @@ -0,0 +1,121 @@ +# The text phonemis feeds the neural model of each language Kokoro phonemizes +# without a lexicon (PreprocessingTest). Format and update command: +# support/Snapshots.h. + +de | Ich habe 25 Katzen. + preprocessed: Ich habe fünfundzwanzig Katzen. +de | Es kostet 4,50 €. + preprocessed: Es kostet vier Euro fünfzig. +de | Am 24.12.2024 fuhren wir. + preprocessed: Am vierundzwanzigsten Dezember zweitausendvierundzwanzig fuhren wir. +de | Um 15:30 Uhr. + preprocessed: Um fünfzehn Uhr dreißig. +de | Der 3. Mai. + preprocessed: Der dritte Mai. +de | Dr. Müller lief z. B. 3,5 km. + preprocessed: Doktor Müller lief zum Beispiel drei Komma fünf Kilometer. +de | Etwa 50 % stimmen zu. + preprocessed: Etwa fünfzig Prozent stimmen zu. +de | Im Jahr 1999. + preprocessed: Im Jahr neunzehnhundertneunundneunzig. + +fr | J'ai 25 chats. + preprocessed: J'ai vingt-cinq chats. +fr | Ça coûte 4,50 €. + preprocessed: Ça coûte quatre euros cinquante. +fr | Le 24/12/2024 nous sommes partis. + preprocessed: Le vingt-quatre décembre deux mille vingt-quatre nous sommes partis. +fr | À 15h30. + preprocessed: À quinze heures trente. +fr | Le 3e jour. + preprocessed: Le troisième jour. +fr | M. Dupont a couru 3,5 km. + preprocessed: monsieur Dupont a couru trois virgule cinq kilomètres. +fr | Environ 50 % sont d'accord. + preprocessed: Environ cinquante pour cent sont d'accord. +fr | En 1999. + preprocessed: En mille neuf cent quatre-vingt-dix-neuf. + +es | Tengo 25 gatos. + preprocessed: Tengo veinticinco gatos. +es | Cuesta 4,50 €. + preprocessed: Cuesta cuatro euros con cincuenta. +es | El 24/12/2024 salimos. + preprocessed: El veinticuatro de diciembre de dos mil veinticuatro salimos. +es | A las 15:30. + preprocessed: A las quince y media. +# Wrong: should be "tercer" (Verbalis#8). +es | El 3.º día. + preprocessed: El tercero día. +es | El Sr. García corrió 3,5 km. + preprocessed: El señor García corrió tres coma cinco kilómetros. +es | Un 50 % está de acuerdo. + preprocessed: Un cincuenta por ciento está de acuerdo. +es | En 1999. + preprocessed: En mil novecientos noventa y nueve. + +it | Ho 25 gatti. + preprocessed: Ho venticinque gatti. +it | Costa 4,50 €. + preprocessed: Costa quattro euro e cinquanta centesimi. +it | Il 24/12/2024 siamo partiti. + preprocessed: Il ventiquattro dicembre duemilaventiquattro siamo partiti. +it | Alle 15:30. + preprocessed: Alle quindici e trenta. +it | Il 3° giorno. + preprocessed: Il terzo giorno. +it | Il Sig. Rossi ha corso 3,5 km. + preprocessed: Il signor Rossi ha corso tre virgola cinque chilometri. +it | Il 50% è d'accordo. + preprocessed: Il cinquanta per cento è d'accordo. +it | Nel 1999. + preprocessed: Nel millenovecentonovantanove. + +pl | Mam 25 kotów. + preprocessed: Mam dwadzieścia pięć kotów. +pl | Kosztuje 4,50 zł. + preprocessed: Kosztuje cztery złote pięćdziesiąt groszy. +pl | Dnia 24.12.2024 wyjechaliśmy. + preprocessed: Dnia dwudziestego czwartego grudnia dwa tysiące dwudziestego czwartego wyjechaliśmy. +pl | O 15:30. + preprocessed: O piętnastej trzydzieści. +pl | 3 maja. + preprocessed: trzeciego maja. +pl | Dr Kowalski przebiegł np. 3,5 km. + preprocessed: Doktor Kowalski przebiegł na przykład trzy i pół kilometra. +pl | Około 50% się zgadza. + preprocessed: Około pięćdziesięciu procent się zgadza. +pl | W 1999 roku. + preprocessed: W tysiąc dziewięćset dziewięćdziesiątym dziewiątym roku. + +pt | Tenho 25 gatos. + preprocessed: Tenho vinte e cinco gatos. +pt | Custa R$ 4,50. + preprocessed: Custa quatro reais e cinquenta centavos. +pt | Em 24/12/2024 partimos. + preprocessed: Em vinte e quatro de dezembro de dois mil e vinte e quatro partimos. +pt | Às 15h30. + preprocessed: Às quinze horas e trinta. +pt | O 3.º dia. + preprocessed: O terceiro dia. +# Wrong: "Sr." should be "senhor" (Verbalis#8). +pt | O Sr. Silva correu 3,5 km. + preprocessed: O Sr. Silva correu três vírgula cinco quilômetros. +pt | Cerca de 50% concordam. + preprocessed: Cerca de cinquenta por cento concordam. +pt | Em 1999. + preprocessed: Em mil novecentos e noventa e nove. + +hi | मेरे पास 25 बिल्लियाँ हैं। + preprocessed: मेरे पास पच्चीस बिल्लियाँ हैं। +hi | इसकी कीमत ₹4.50 है। + preprocessed: इसकी कीमत चार रुपये पचास पैसे है। +hi | 24/12/2024 को हम गए। + preprocessed: चौबीस दिसंबर दो हज़ार चौबीस को हम गए। +# Wrong: says बजे twice (Verbalis#8). +hi | 3:30 बजे। + preprocessed: तीन बजकर तीस मिनट बजे। +hi | 50% लोग सहमत हैं। + preprocessed: पचास प्रतिशत लोग सहमत हैं। +hi | 1999 में। + preprocessed: एक हज़ार नौ सौ निन्यानवे में। diff --git a/packages/react-native-executorch/cpp/tests/support/Snapshots.cpp b/packages/react-native-executorch/cpp/tests/support/Snapshots.cpp new file mode 100644 index 0000000000..cb1e92f8e8 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/support/Snapshots.cpp @@ -0,0 +1,107 @@ +#include "support/Snapshots.h" + +#include +#include +#include +#include +#include + +#include + +namespace rnexecutorch::tests::snapshots { +namespace { + +constexpr std::string_view kCaseSeparator = " | "; +constexpr std::string_view kValueIndent = " "; +constexpr std::string_view kValueSeparator = ": "; + +bool updating() { + const char *flag = std::getenv("RNE_UPDATE_SNAPSHOTS"); + return flag != nullptr && std::string_view(flag) == "1"; +} + +void write(const std::string &path, const std::vector &cases, const std::vector &trailing) { + std::ofstream out(path); + for (const auto &c : cases) { + for (const auto &comment : c.comments) { + out << comment << '\n'; + } + out << c.lang << kCaseSeparator << c.input << '\n'; + for (const auto &[key, value] : c.values) { + out << kValueIndent << key << kValueSeparator << value << '\n'; + } + } + for (const auto &comment : trailing) { + out << comment << '\n'; + } +} + +// The cases, plus the comment lines after the last one. +std::pair, std::vector> parse(const std::string &path) { + std::ifstream in(path); + if (!in) { + throw std::runtime_error("cannot open snapshot file " + path); + } + std::vector cases; + std::vector comments; + std::string line; + while (std::getline(in, line)) { + if (line.empty() || line.starts_with('#')) { + comments.push_back(line); + } else if (line.starts_with(kValueIndent)) { + auto separator = line.find(kValueSeparator); + if (cases.empty() || separator == std::string::npos) { + throw std::runtime_error("malformed snapshot line in " + path + ": " + line); + } + cases.back().values.emplace_back(line.substr(kValueIndent.size(), separator - kValueIndent.size()), + line.substr(separator + kValueSeparator.size())); + } else { + auto separator = line.find(kCaseSeparator); + if (separator == std::string::npos) { + throw std::runtime_error("malformed snapshot line in " + path + ": " + line); + } + cases.push_back({.lang = line.substr(0, separator), + .input = line.substr(separator + kCaseSeparator.size()), + .values = {}, + .comments = std::move(comments)}); + comments.clear(); + } + } + return {std::move(cases), std::move(comments)}; +} + +} // namespace + +std::vector read(const std::string &path) { return parse(path).first; } + +void verify(const std::string &path, const std::function(const std::vector &)> &produce) { + auto [cases, trailing] = parse(path); + auto actual = produce(cases); + ASSERT_EQ(actual.size(), cases.size()); + + if (updating()) { + for (size_t i = 0; i < cases.size(); ++i) { + cases[i].values = std::move(actual[i]); + } + write(path, cases, trailing); + return; + } + + for (size_t i = 0; i < cases.size(); ++i) { + if (cases[i].values != actual[i]) { + std::ostringstream message; + message << "snapshot of [" << cases[i].lang << "] " << cases[i].input << " changed\n"; + for (const auto &[key, value] : cases[i].values) { + message << " - " << key << kValueSeparator << value << '\n'; + } + for (const auto &[key, value] : actual[i]) { + message << " + " << key << kValueSeparator << value << '\n'; + } + message << "Accept with RNE_UPDATE_SNAPSHOTS=1 scripts/run-native-tests.sh, then review the diff of " + << path; + ADD_FAILURE() << message.str(); + } + } +} + +} // namespace rnexecutorch::tests::snapshots diff --git a/packages/react-native-executorch/cpp/tests/support/Snapshots.h b/packages/react-native-executorch/cpp/tests/support/Snapshots.h new file mode 100644 index 0000000000..9a1f023f97 --- /dev/null +++ b/packages/react-native-executorch/cpp/tests/support/Snapshots.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include +#include + +namespace rnexecutorch::tests::snapshots { + +/** + * Snapshot files pin what a third-party dependency produces (phonemis's + * readings) without hard-coding it in the tests, so a bump that changes the + * output is one command to accept and a diff to review, not strings to retype: + * + * RNE_UPDATE_SNAPSHOTS=1 scripts/run-native-tests.sh -R + * + * A file is a list of cases. Each starts with a ` | ` line and + * holds one indented `: ` line per output. Lines starting with `#` + * and blank lines are comments and survive an update; a case added without + * values is filled in by the next one. + */ + +using Values = std::vector>; + +struct Case { + std::string lang; + std::string input; + Values values; + // Comment lines just above the case. + std::vector comments; +}; + +std::vector read(const std::string &path); + +/** + * Compares what `produce` returns for each case, in order, with the file. + * With RNE_UPDATE_SNAPSHOTS=1 it rewrites the file instead, and passes. + */ +void verify(const std::string &path, const std::function(const std::vector &)> &produce); + +} // namespace rnexecutorch::tests::snapshots diff --git a/packages/react-native-executorch/react-native-executorch.podspec b/packages/react-native-executorch/react-native-executorch.podspec index bf9921f91a..a412d21a42 100644 --- a/packages/react-native-executorch/react-native-executorch.podspec +++ b/packages/react-native-executorch/react-native-executorch.podspec @@ -1,5 +1,6 @@ require "fileutils" require "json" +require_relative "third-party/common/phonemis/phonemis_sources" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) @@ -99,10 +100,10 @@ Pod::Spec.new do |s| # phonemis is built from in-tree source (third-party/common/phonemis submodule); # its runner entrypoint is excluded so only the library sources compile. + phonemis_root = "third-party/common/phonemis" phonemis_source_files = [ "cpp/extensions/speech/phonemizer.{cpp,h}", - "third-party/common/phonemis/src/**/*.{cpp,hpp,h}", - ] + ] + PhonemisSources.source_files(phonemis_root) source_files = [ "ios/**/*.{h,m,mm}", @@ -114,8 +115,7 @@ Pod::Spec.new do |s| # cpp/tests holds the host GoogleTest suites, built by cpp/tests/CMakeLists.txt # and never by the app: `cpp/**` above sweeps them in, and the pod carries no # googletest headers, so an app build fails on . - exclude_files = [ - "third-party/common/phonemis/src/phonemis/main.cpp", + exclude_files = PhonemisSources.exclude_files(phonemis_root) + [ "cpp/tests/**/*", ] exclude_files += opencv_source_files unless enable_opencv @@ -253,7 +253,7 @@ Pod::Spec.new do |s| "$(inherited)", "EXECUTORCH_ENABLE_EXECUTION_PROFILING=1", ].join(' '), - "HEADER_SEARCH_PATHS" => [ + "HEADER_SEARCH_PATHS" => ([ "\"$(PODS_TARGET_SRCROOT)/cpp\"", "\"$(PODS_TARGET_SRCROOT)/#{third_party_include}\"", "\"$(PODS_TARGET_SRCROOT)/third-party/include/cpuinfo\"", @@ -262,10 +262,7 @@ Pod::Spec.new do |s| "\"$(PODS_TARGET_SRCROOT)/third-party/include/executorch/extension/llm/tokenizers/third-party/json/include\"", "\"$(PODS_TARGET_SRCROOT)/third-party/include/executorch/extension/llm/tokenizers/third-party/re2\"", "\"$(PODS_TARGET_SRCROOT)/third-party/include/executorch/extension/llm/tokenizers/third-party/abseil-cpp\"", - "\"$(PODS_TARGET_SRCROOT)/third-party/common/phonemis/src\"", - # phonemis's vendored xsimd includes itself as `xsimd/...` (its CMakeLists adds this too). - "\"$(PODS_TARGET_SRCROOT)/third-party/common/phonemis/src/third-party\"", - ].join(' '), + ] + PhonemisSources.header_search_paths(phonemis_root).map { |p| "\"$(PODS_TARGET_SRCROOT)/#{p}\"" }).join(' '), "WARNING_CFLAGS" => "-Wno-documentation", 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'x86_64', } diff --git a/packages/react-native-executorch/scripts/create-package.sh b/packages/react-native-executorch/scripts/create-package.sh index 1450f932d1..c87898fe56 100755 --- a/packages/react-native-executorch/scripts/create-package.sh +++ b/packages/react-native-executorch/scripts/create-package.sh @@ -6,7 +6,7 @@ set -euo pipefail # from packages/react-native-executorch. # Phonemis is a git submodule whose sources the podspec compiles directly -# (see third-party/common/phonemis/src in react-native-executorch.podspec). +# (listed by third-party/common/phonemis/phonemis_sources.rb, which the podspec requires). # Init it explicitly so the files are present in the packed tarball. # Run from repo root so the submodule path resolves regardless of cwd. git -C "$(git rev-parse --show-toplevel)" submodule update --init --recursive \ @@ -17,6 +17,8 @@ git -C "$(git rev-parse --show-toplevel)" submodule update --init --recursive \ # `!scripts/build*` which npm-packlist honors and re-includes those files # despite our exclusion rules. Restore on exit so the working tree stays clean. PHONEMIS_DIR="third-party/common/phonemis" +# Of Verbalis, the podspec compiles only cpp/; keep it and the license files. +VERBALIS_DIR="$PHONEMIS_DIR/third-party/verbalis" # npm only picks up a LICENSE that sits in the package directory, and ours # lives at the repo root, so the published tarball carried no license text at @@ -26,12 +28,16 @@ PHONEMIS_DIR="third-party/common/phonemis" cp "$(git rev-parse --show-toplevel)/LICENSE" LICENSE cleanup() { - git -C "$PHONEMIS_DIR" checkout -- data test scripts requirements.txt 2>/dev/null || true + git -C "$PHONEMIS_DIR" checkout -- . 2>/dev/null || true + git -C "$VERBALIS_DIR" checkout -- . 2>/dev/null || true rm -f LICENSE } trap cleanup EXIT -rm -rf "$PHONEMIS_DIR/data" "$PHONEMIS_DIR/test" "$PHONEMIS_DIR/scripts" -rm -f "$PHONEMIS_DIR/requirements.txt" +rm -rf "$PHONEMIS_DIR/data" "$PHONEMIS_DIR/test" "$PHONEMIS_DIR/scripts" "$PHONEMIS_DIR/assets" +rm -f "$PHONEMIS_DIR/requirements.txt" "$PHONEMIS_DIR/readme.source.md" +find "$VERBALIS_DIR" -mindepth 1 -maxdepth 1 \ + ! -name .git ! -name cpp ! -name LICENSE ! -name licenses ! -name THIRD_PARTY_NOTICES.md \ + -exec rm -rf {} + # The publish workflow installs before calling this script, so it sets # RNE_SKIP_INSTALL to avoid a second pass. A local run still installs. diff --git a/packages/react-native-executorch/scripts/fetch-test-fixtures.sh b/packages/react-native-executorch/scripts/fetch-test-fixtures.sh index f1440f0805..238d47e03c 100755 --- a/packages/react-native-executorch/scripts/fetch-test-fixtures.sh +++ b/packages/react-native-executorch/scripts/fetch-test-fixtures.sh @@ -12,8 +12,13 @@ # * A HuggingFace tokenizer.json, which the nlp extension loads through # ExecuTorch's HFTokenizer. Whisper tiny.en's is a plain BPE vocabulary, # ~2.4 MB. +# * Kokoro's phonemizer data for the languages it phonemizes without a +# neural model: the en-us tagger (en-gb's is the same file), the en-us and +# en-gb lexicons, and the zh segmenter and lexicon (~26 MB together). With +# them phonemis produces real phonemes, so the phonemizer's text +# normalization and word locating are pinned end to end. # -# Both are pinned to an exact Hugging Face revision and verified against a +# All are pinned to an exact Hugging Face revision and verified against a # recorded sha256, so a re-tag upstream cannot silently change what the tests # assert. Idempotent: a no-op when a fixture is already present and matches. # @@ -43,7 +48,7 @@ fetch_fixture() { return fi - mkdir -p "$FIXTURE_DIR" + mkdir -p "$(dirname "$target")" local url="https://huggingface.co/${repo}/resolve/${revision}/${path}" echo "↓ ${url}" curl -fsSL -o "${target}.tmp" "$url" @@ -75,3 +80,38 @@ fetch_fixture \ "c99612ff807ef223f6316f33a4be7c587835a5ce" \ "tokenizer.json" \ "5eb60cec1e77aeeb6869a2bb5a8e01a84c3fe5d072d75369343021fe6f5310d0" + +fetch_fixture \ + "phonemizer/en-us/tags.json" \ + "software-mansion/Kokoro-82M-ExecuTorch" \ + "4836d50e0fa48d7cdd415210f6c2c0e1acba5acb" \ + "phonemizer/en-us/tags.json" \ + "028f7d6a0ee7638d91fab27ef8809c0b36de312e6409b6b8e844bffd0871e3e7" + +fetch_fixture \ + "phonemizer/en-us/lexicon.json" \ + "software-mansion/Kokoro-82M-ExecuTorch" \ + "4836d50e0fa48d7cdd415210f6c2c0e1acba5acb" \ + "phonemizer/en-us/lexicon.json" \ + "b29e9c13190cf211979e8d9c38258cc1cb8e701e5ca1102a0c1f00acd4f55f8e" + +fetch_fixture \ + "phonemizer/en-gb/lexicon.json" \ + "software-mansion/Kokoro-82M-ExecuTorch" \ + "4836d50e0fa48d7cdd415210f6c2c0e1acba5acb" \ + "phonemizer/en-gb/lexicon.json" \ + "f4ad98b7725c681be79df533288e20df71db40a89d0cfdead2192f0d61449399" + +fetch_fixture \ + "phonemizer/zh/segmenter.json" \ + "software-mansion/Kokoro-82M-ExecuTorch" \ + "4836d50e0fa48d7cdd415210f6c2c0e1acba5acb" \ + "phonemizer/zh/segmenter.json" \ + "4079bc04a9028e7fb0e7b015a327b5c65301feb3069d4ba391ff823fa357c200" + +fetch_fixture \ + "phonemizer/zh/lexicon.json" \ + "software-mansion/Kokoro-82M-ExecuTorch" \ + "4836d50e0fa48d7cdd415210f6c2c0e1acba5acb" \ + "phonemizer/zh/lexicon.json" \ + "f43304c9c2426545f8491c89ba235bab9e5bd740fdd42c4eeaca6df216f20735" diff --git a/packages/react-native-executorch/third-party/README.md b/packages/react-native-executorch/third-party/README.md index ed292fd314..4570d6d28e 100644 --- a/packages/react-native-executorch/third-party/README.md +++ b/packages/react-native-executorch/third-party/README.md @@ -9,7 +9,8 @@ Native ExecuTorch artifacts are split into **committed source** and static archives into `ExecutorchLib.xcframework` (used only when (re)building the iOS release artifacts). - `common/phonemis` — git submodule (TTS phonemizer), built from source. Run - `git submodule update --init` to fetch it. + `git submodule update --init --recursive` to fetch it with Verbalis, its nested + submodule. ## Downloaded on demand (NOT committed) diff --git a/packages/react-native-executorch/third-party/common/phonemis b/packages/react-native-executorch/third-party/common/phonemis index d2595d8136..5ec260e331 160000 --- a/packages/react-native-executorch/third-party/common/phonemis +++ b/packages/react-native-executorch/third-party/common/phonemis @@ -1 +1 @@ -Subproject commit d2595d8136aa51fd6a55b8bfe2e940a6cd2f063d +Subproject commit 5ec260e33127de044bda7147f52cea27a7e2e491