DotNetG2P 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetG2P --version 1.0.0
                    
NuGet\Install-Package DotNetG2P -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetG2P" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetG2P" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DotNetG2P" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetG2P --version 1.0.0
                    
#r "nuget: DotNetG2P, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetG2P@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetG2P&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DotNetG2P&version=1.0.0
                    
Install as a Cake Tool

DotNetG2P

CI NuGet License: Apache-2.0

C#/.NET向け日本語G2P(Grapheme-to-Phoneme: 書記素→音素変換)ライブラリ。 OpenJTalk互換のルールベースG2Pパイプラインを C# でネイティブに再実装し、Pythonやネイティブバイナリへの依存なしに日本語テキストを音素列に変換します。

using var engine = new G2PEngine(new MeCabTokenizer("/path/to/naist-jdic"));

engine.ToPhonemes("こんにちは");  // => "k o N n i ch i w a"
engine.ToKana("音声合成");        // => "オンセーゴーセー"

目次

特徴

  • 純C#実装 — ネイティブバイナリ不要、独自MeCabエンジン(DotNetG2P.MeCab)によりNuGetパッケージ依存なし(実行時にnaist-jdic辞書が必要)
  • OpenJTalk互換パイプライン — 発音生成・数字読み・アクセント句結合・アクセント結合型・無声音化の6段階NJD処理
  • 複数の出力形式 — 音素列 / カタカナ / ESPnet韻律記号 / VOICEVOX互換AccentPhrase / HTSフルコンテキストラベル
  • Unity対応 — .NET Standard 2.1(Unity 2021.2+)ターゲット、UPMパッケージ提供
  • 拡張可能な設計ITokenizerインターフェースにより形態素解析エンジンを差し替え可能

インストール

NuGet

# コアライブラリ + 独自MeCabエンジン
dotnet add package DotNetG2P
dotnet add package DotNetG2P.MeCab

パッケージ構成

パッケージ ライセンス 説明
DotNetG2P Apache-2.0 コアライブラリ(G2Pエンジン、NJD処理、音素変換)
DotNetG2P.MeCab Apache-2.0 独自MeCabエンジン(外部依存なし)

Unity (UPM)

Unity Package Managerの Add package from git URL で以下を追加:

https://github.com/ayutaz/dot-net-g2p.git?path=src/DotNetG2P.Core
https://github.com/ayutaz/dot-net-g2p.git?path=src/DotNetG2P.MeCab

Note: 別途 naist-jdic 辞書が必要です。詳細は辞書の準備を参照してください。

クイックスタート

using DotNetG2P;
using DotNetG2P.MeCab;

// 1. エンジン初期化(辞書パスを指定)
using var tokenizer = new MeCabTokenizer("/path/to/naist-jdic");
using var engine = new G2PEngine(tokenizer);

// 2. テキストから音素列を取得
string phonemes = engine.ToPhonemes("今日は良い天気です");
// => "ky o o w a i i t e N k i d e s U"

// 3. カタカナ読みを取得
string kana = engine.ToKana("今日は良い天気です");
// => "キョーワイーテンキデス"

// 4. 韻律記号付き出力(ESPnet方式)
string prosody = engine.ToProsody("こんにちは");
// => "^ k o [ N n i ch i w a $"

// 5. VOICEVOX互換アクセント句
var phrases = engine.ToAccentPhrases("こんにちは");

// 6. HTSフルコンテキストラベル(HMM/DNN音声合成用)
var labels = engine.ToFullContextLabels("こんにちは");

API リファレンス

G2PEngine

メソッド 戻り値型 説明
ToPhonemes(text) string 空白区切り音素列 ("k o N n i ch i w a")
ToKana(text) string カタカナ読み ("コンニチワ")
ToProsody(text) string ESPnet韻律記号付き ("^ k o [ N n i ch i w a $")
ToAccentPhrases(text) IReadOnlyList<AccentPhrase> VOICEVOX互換アクセント句構造体
ToFullContextLabels(text) IReadOnlyList<string> HTSフルコンテキストラベル
Analyze(text) IReadOnlyList<NjdNode> NJD処理後のノード列
ToPhonemesBatch(texts) IReadOnlyList<string> 複数テキストを一括で音素列に変換
ToKanaBatch(texts) IReadOnlyList<string> 複数テキストを一括でカタカナ読みに変換
ToProsodyBatch(texts) IReadOnlyList<string> 複数テキストを一括で韻律記号付きに変換
ToFullContextLabelsBatch(texts) IReadOnlyList<IReadOnlyList<string>> 複数テキストを一括でHTSラベルに変換

日本語音素体系

種別 音素
母音 a i u e o (無声: A I U E O
子音 k g s z t d n h b p m r f v
拗音子音 ky gy sh j ch ts ny hy by py my ry dy ty kw gw
半母音 y w
特殊 N(撥音) cl(促音) -(長音) pau(ポーズ)

処理パイプライン

DotNetG2PはOpenJTalkと同等の6段階NJD処理パイプラインを実装しています。

テキスト入力
  │
  ├─ TextNormalizer        全角/半角正規化、濁点結合
  ├─ ITokenizer.Tokenize   形態素解析(MeCabTokenizer + naist-jdic)
  ├─ SetPronunciation      辞書読み・フォールバック発音生成
  ├─ SetDigit              数字列検出・助数詞読み変換
  ├─ SetAccentPhrase       品詞パターンによるアクセント句結合(18ルール)
  ├─ SetAccentType         チェインルールによるアクセント結合型決定
  └─ SetUnvoicedVowel      無声母音化(6ルール)
  │
  ▼
  出力(音素列 / カタカナ / 韻律記号 / AccentPhrase / HTSラベル)

辞書の準備

DotNetG2Pは形態素解析にnaist-jdic辞書(OpenJTalk用MeCab辞書)を使用します。

入手方法

  1. Open JTalk公式サイトからダウンロード
  2. pyopenjtalkやOpenJTalkに同梱の辞書ディレクトリをそのまま使用

必要なファイル

辞書ディレクトリに以下の4ファイルが含まれている必要があります:

ファイル 内容
sys.dic システム辞書
matrix.bin 遷移コスト行列
char.bin 文字カテゴリ定義
unk.dic 未知語テンプレート

Unity での配置

Unityでは StreamingAssets フォルダに辞書ファイルを配置し、Application.streamingAssetsPath を使用してパスを指定します。

var dicPath = Path.Combine(Application.streamingAssetsPath, "naist-jdic");
using var tokenizer = new MeCabTokenizer(dicPath);

オプション設定

G2POptions で各処理段階を個別にON/OFFできます(イミュータブル設計)。

// 無声音化のみ無効にする例
var options = new G2POptions(enableUnvoicedVowel: false);
using var engine = new G2PEngine(tokenizer, options);
パラメータ デフォルト 説明
enableTextNormalization true テキスト正規化(全角/半角変換)
enableDigitProcessing true 数字読み変換・助数詞処理
enableAccentPhrase true アクセント句結合(18ルール)
enableAccentType true アクセント結合型決定
enableUnvoicedVowel true 無声母音化(6ルール)

ビルド

要件

  • .NET SDK 9.0 以上

コマンド

# ビルド
dotnet build DotNetG2P.slnx

# テスト実行
dotnet test DotNetG2P.slnx

# コンソールサンプル(辞書なし: MoraMappingのみ確認)
dotnet run --project samples/DotNetG2P.Console

# コンソールサンプル(辞書あり: フルG2P)
dotnet run --project samples/DotNetG2P.Console -- /path/to/naist-jdic

ライセンス

パッケージ ライセンス 備考
DotNetG2P Apache-2.0 コアライブラリ
DotNetG2P.MeCab Apache-2.0 独自MeCabエンジン

全コンポーネントがApache-2.0ライセンスで利用可能です。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DotNetG2P:

Package Downloads
DotNetG2P.MeCab

Pure C# MeCab-compatible morphological analyzer for DotNetG2P. Apache-2.0 licensed, no native dependencies. Provides ITokenizer implementation using Darts-clone double-array trie and Viterbi decoder for Japanese text analysis with naist-jdic dictionary.

DotNetG2P.Multilingual

Multilingual G2P engine combining Japanese, English, Chinese, Korean, Spanish, French, Portuguese, and Swedish grapheme-to-phoneme support with automatic language detection.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.0 192 4/13/2026
1.9.0 187 4/2/2026
1.8.2 174 3/21/2026
1.8.1 172 3/20/2026
1.8.0 2,958 3/20/2026
1.7.0 172 3/18/2026
1.6.0 178 3/17/2026
1.5.0 176 3/15/2026
1.4.0 205 3/12/2026
1.3.0 179 3/10/2026
1.2.0 173 3/7/2026
1.1.0 136 3/5/2026
1.0.0 144 3/3/2026