Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js向けのFFIを実装 #758

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a12e6d2
Node.jsでFFIを実装するドラフトPRのための空コミット
takejohn Feb 28, 2024
7f871a3
napi-rsで初期化
takejohn Feb 28, 2024
ea809fb
prettierを導入してインデントをスペース4個に
takejohn Feb 28, 2024
a507b62
Revert "prettierを導入してインデントをスペース4個に"
takejohn Feb 28, 2024
a3584d3
Rustのインデントをスペース4個に変更
takejohn Feb 28, 2024
c418030
Prettierで一部ファイルのインデントをスペース4個に
takejohn Feb 28, 2024
cd04f47
Merge branch 'main' into feature/550-ffi-napi-rs
takejohn Mar 5, 2024
8a2462f
SupportedDevices対応
takejohn Mar 5, 2024
58ef4bb
SupportedDevices.toJsonメソッドを追加
takejohn Mar 8, 2024
04eee9a
元のソースに対応してファイル分け
takejohn Mar 8, 2024
2386695
クレートに対するアトリビュートを移動
takejohn Mar 8, 2024
e1fe417
モデルの型定義
takejohn Mar 8, 2024
bc6360f
サンプルのテストコードを削除
takejohn Mar 8, 2024
cfd1c71
ドキュメンテーションコメントの補完
takejohn Mar 8, 2024
020e0dd
自動生成されるd.ts, jsファイルをvcsから除外
takejohn Mar 8, 2024
4dd1052
blocking API作成開始
takejohn Mar 9, 2024
17a572f
UserDictの実装
takejohn Mar 9, 2024
e8e16dd
blocking名前空間のコードを移動
takejohn Mar 15, 2024
de13bf5
Synthesizerクラス作成
takejohn Mar 15, 2024
0f10872
VoiceModelクラスの実装
takejohn Mar 16, 2024
c3eac14
メソッド追加
takejohn Mar 16, 2024
b4e1251
さらにメソッド追加
takejohn Mar 17, 2024
3a63e2a
音声合成のメソッドを追加
takejohn Mar 17, 2024
eda6086
ドキュメンテーションとアトリビュートを追加
takejohn Mar 17, 2024
8c7203f
テストの作成
takejohn Mar 17, 2024
0988e9f
UserDictのテストを作成
takejohn Mar 17, 2024
dac865a
Synthesizerのテストを作成
takejohn Mar 18, 2024
230da3e
SynthesizerのisGpuModeとmetasをgetterに
takejohn Mar 18, 2024
1abc435
Java APIからテストを移植
takejohn Mar 18, 2024
023a5d3
UserDictWordのデフォルト値を指定
takejohn Mar 18, 2024
e98b733
Python APIのユーザー辞書のテストを移植
takejohn Mar 18, 2024
4eef4f1
Promise版APIを作成
takejohn Mar 18, 2024
0b7890f
コードの共通化
takejohn Mar 18, 2024
c9445e3
Prettierで整形
takejohn Mar 18, 2024
156dfb1
パッケージ名をvoicevox_coreに変更
takejohn Mar 18, 2024
4906eac
エクスポートを明示的に
takejohn Mar 18, 2024
ed215a7
テストでvoicevox_coreとしてインポート
takejohn Mar 18, 2024
427661d
blocking,promisesをそれぞれモジュールとしてエクスポート
takejohn Mar 18, 2024
a2a2251
README作成
takejohn Mar 20, 2024
15e7cbe
npmパッケージの名前を変更
takejohn Mar 20, 2024
c5c52ea
docsスクリプトを作成
takejohn Mar 20, 2024
950a7b3
'run' を省略
takejohn Mar 20, 2024
7d45fda
パッケージマネージャをnpmに変更
takejohn Mar 22, 2024
d6fcae9
npmディレクトリを削除
takejohn Mar 22, 2024
14e6e3d
Prettierのルールをデフォルトに変更
takejohn Mar 22, 2024
55e6e00
handleメンバ名を変更
takejohn Mar 22, 2024
6d6e619
Merge branch 'main' into feature/550-ffi-napi-rs
takejohn May 16, 2024
48f3bb6
node依存パッケージのアップデート
takejohn May 16, 2024
8ffbc91
他のクレートに倣ってCargo.tomlを修正
takejohn May 23, 2024
72af516
ルートのCargo.tomlからfeatureの指定を削除
takejohn May 23, 2024
046618b
改行を追加
takejohn May 23, 2024
e04da34
フォーマットの設定がデフォルト値のため削除
takejohn May 23, 2024
d97ecc7
Merge branch 'main' into feature/550-ffi-napi-rs
takejohn May 23, 2024
aaefb43
featuresにcudaを追加
takejohn May 23, 2024
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
2,057 changes: 1,075 additions & 982 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ log = "0.4.17"
nanoid = "0.4.0"
ndarray = "0.15.6"
ndarray-stats = "0.5.1"
napi = { version = "2.12.2", default-features = false }
napi-derive = "2.12.2"
octocrab = { version = "0.19.0", default-features = false }
once_cell = "1.18.0"
ouroboros = "0.18.0"
Expand Down
5 changes: 5 additions & 0 deletions crates/voicevox_core_node_api/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
203 changes: 203 additions & 0 deletions crates/voicevox_core_node_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.toptal.com/developers/gitignore/api/node

# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos

# Created by https://www.toptal.com/developers/gitignore/api/windows
# Edit at https://www.toptal.com/developers/gitignore?templates=windows

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows

#Added by cargo

/target
Cargo.lock

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

*.node

# Manually added

/index.d.ts
/index.js
/docs/
13 changes: 13 additions & 0 deletions crates/voicevox_core_node_api/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target
Cargo.lock
.cargo
.github
npm
.eslintrc
.prettierignore
rustfmt.toml
yarn.lock
*.node
.yarn
__test__
renovate.json
3 changes: 3 additions & 0 deletions crates/voicevox_core_node_api/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.yarn/
index.js
*.md
893 changes: 893 additions & 0 deletions crates/voicevox_core_node_api/.yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/voicevox_core_node_api/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.0.cjs
23 changes: 23 additions & 0 deletions crates/voicevox_core_node_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "voicevox_core_node_api"
version = "0.0.0"
edition.workspace = true
publish.workspace = true

[lib]
crate-type = ["cdylib"]

qryxip marked this conversation as resolved.
Show resolved Hide resolved
[features]
cuda = ["voicevox_core/cuda"]
directml = ["voicevox_core/directml"]

[dependencies]
napi = { version = "2.16.0", features = ["napi4", "serde-json", "tokio_rt"] }
napi-derive = "2.16.0"
voicevox_core.workspace = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#802 (comment)

Suggested change
voicevox_core.workspace = true
voicevox_core = { workspace = true, features = ["load-onnxruntime"] }

serde.workspace = true
serde_json.workspace = true
uuid.workspace = true

[build-dependencies]
napi-build = "2"
56 changes: 56 additions & 0 deletions crates/voicevox_core_node_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# voicevox_core_node_api

VOICEVOX CORE の Node.js バインディングです。

## 環境構築

以下の環境が必要です。

- Rustup
- Node > 10.0.0

## ファイル構成

```console
.
├── build.rs
├── Cargo.toml : Rust プロジェクトとしてのマニフェストファイルです。
├── exports : blocking および promises 名前空間下のクラスを再エクスポートするためのモジュールです。
│ ├── blocking.d.ts
│ ├── blocking.js
│ ├── promises.d.ts
│ └── promises.js
├── package.json
├── README.md
├── src : Rust で書かれたソースファイルです。
│ └── ...
├── __test__ : TypeScript と AVA によるテストのソースファイルです。
│ └── ...
├── tsconfig.json
└── yarn.lock
```

## ビルド

npm で依存ライブラリをダウンロードし、`build` タスクによって `index.d.ts`, `index.js` および `node` 拡張子のネイティブモジュールを生成します。

```console
❯ npm install
❯ npm run build
```

## テスト

`npm test` でテストを行うことができます。

```console
❯ npm test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テスト前にcargo build -p test_utilが要るんじゃないかと思います。
(クリーンなリポジトリからvoicevox_core_node_apiだけビルドした場合、crates/test_util/dataは生成されない)

参考:

- run: cargo build -p test_util -vv # build scriptにより/crates/test_util/data/の生成

cargo build -p test_util -vv # build scriptにより/crates/test_util/data/の生成

npm test内に仕込むのがいいかもしれませんが、どうやるかは私にはよくわからないです。なんかnpm-run-all2っていう、かつてのnpm-run-allのフォークがあるっぽい…?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test": "run-s test:build-util test:ava",
"test:build-util": "cargo build -p test_util",
"test:ava": "ava"

npm-run-all2使うとこんな感じだと思います。
まぁ直列ならOS差は困るほどはないので、

"test": "cargo build -p test_util && ava"

でいいかも。avaにセットアップのHookがあるならそれでビルドしてもいいかも?

```

## ドキュメント

`npm run docs` でドキュメントを生成できます。

```console
❯ npm run docs
```
37 changes: 37 additions & 0 deletions crates/voicevox_core_node_api/__test__/_testUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import path from "path";
import { AccentPhrase, Mora } from "voicevox_core";

export const openJtalkDicDir = path.join(
__dirname,
"..",
"..",
"test_util",
"data",
"open_jtalk_dic_utf_8-1.11",
);
export const modelFile = path.join(
__dirname,
"..",
"..",
"..",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#791 (comment)

Suggested change
"..",
"test_util",
"data",

"model",
"sample.vvm",
);

export function checkAllMoras(
accentPhrases: AccentPhrase[],
otherAccentPhrases: AccentPhrase[],
checker: (mora: Mora, otherMora: Mora) => boolean,
): boolean {
for (let i = 0; i < accentPhrases.length; i++) {
const accentPhrase = accentPhrases[i];
for (let j = 0; j < accentPhrase.moras.length; j++) {
const mora = accentPhrase.moras[j];
const otherMora = otherAccentPhrases[i].moras[j];
if (!checker(mora, otherMora)) {
return false;
}
}
}
return true;
}
Loading
Loading