Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 22 additions & 15 deletions Assets/uDesktopMascot/Scripts/Dialog/ChatDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
Expand All @@ -10,14 +12,15 @@
using UnityEngine.Localization.Components;
using UnityEngine.UI;
using Button = UnityEngine.UI.Button;
using DotNetG2P;
using DotNetG2P.MeCab;
using uPiper.Core;
using uPiper.Core.AudioGeneration;
using uPiper.Core.Logging;
using uPiper.Core.Phonemizers;
using Unity.InferenceEngine;
using Newtonsoft.Json.Linq;
using System.Linq;
using uPiper.Core.Phonemizers.Implementations;

namespace uDesktopMascot
{
Expand Down Expand Up @@ -108,7 +111,8 @@ public class ChatDialog : DialogBase
private InferenceAudioGenerator _ttsGenerator;
private PhonemeEncoder _phonemeEncoder;
private AudioClipBuilder _audioClipBuilder;
private OpenJTalkPhonemizer _japanesePhonemizer;
private G2PEngine _g2pEngine;
private MeCabTokenizer _mecabTokenizer;
private PiperVoiceConfig _ttsVoiceConfig;
private bool _isTTSInitialized = false;

Expand Down Expand Up @@ -391,16 +395,19 @@ private async void InitializeTTS()
_ttsGenerator = new InferenceAudioGenerator();
_audioClipBuilder = new AudioClipBuilder();

// OpenJTalk phonemizerを初期化
// DotNetG2P (MeCab + G2PEngine) を初期化
try
{
_japanesePhonemizer = new OpenJTalkPhonemizer();
PiperLogger.LogInfo("[ChatDialog] OpenJTalk phonemizer initialized successfully");
var dicPath = Path.Combine(Application.streamingAssetsPath, "uPiper", "OpenJTalk", "naist_jdic", "open_jtalk_dic_utf_8-1.11");
_mecabTokenizer = new MeCabTokenizer(dicPath);
_g2pEngine = new G2PEngine(_mecabTokenizer);
PiperLogger.LogInfo("[ChatDialog] DotNetG2P engine initialized successfully");
}
catch (Exception ex)
{
PiperLogger.LogError($"[ChatDialog] Failed to initialize OpenJTalk: {ex.Message}");
_japanesePhonemizer = null;
PiperLogger.LogError($"[ChatDialog] Failed to initialize DotNetG2P: {ex.Message}");
_g2pEngine = null;
_mecabTokenizer = null;
return;
}

Expand Down Expand Up @@ -527,17 +534,16 @@ private async UniTask SynthesizeAndPlayTTS(string text)
{
PiperLogger.LogInfo($"[ChatDialog] Starting TTS synthesis for text: {text}");

// OpenJTalkで音素に変換
var phonemizer = new TextPhonemizerAdapter(_japanesePhonemizer);
var phonemeResult = await phonemizer.PhonemizeAsync(text, "ja");
var openJTalkPhonemes = phonemeResult.Phonemes;

// DotNetG2Pで音素に変換
var phonemeString = await Task.Run(() => _g2pEngine.ToPhonemes(text));
var openJTalkPhonemes = phonemeString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

PiperLogger.LogInfo($"[ChatDialog] OpenJTalk phonemes: {string.Join(" ", openJTalkPhonemes)}");

// Piper形式の音素に変換
var piperPhonemes = OpenJTalkToPiperMapping.ConvertToPiperPhonemes(openJTalkPhonemes);
PiperLogger.LogInfo($"[ChatDialog] Piper phonemes: {string.Join(" ", piperPhonemes)}");

// 音素をIDに変換
var phonemeIds = _phonemeEncoder.Encode(piperPhonemes);
PiperLogger.LogInfo($"[ChatDialog] Phoneme IDs: {string.Join(", ", phonemeIds)}");
Expand Down Expand Up @@ -619,7 +625,8 @@ private void OnDestroy()

// 音声合成関連のリソースを解放
_ttsGenerator?.Dispose();
_japanesePhonemizer?.Dispose();
_g2pEngine?.Dispose();
_mecabTokenizer?.Dispose();
}

/// <summary>
Expand Down
8 changes: 0 additions & 8 deletions Assets/uPiper.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/uPiper/Plugins.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/uPiper/Plugins/Windows.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/uPiper/Plugins/Windows/x86_64.meta

This file was deleted.

Binary file not shown.

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/uPiper/Plugins/macOS.meta

This file was deleted.

35 changes: 0 additions & 35 deletions Assets/uPiper/Plugins/macOS/openjtalk_wrapper.bundle.meta

This file was deleted.

This file was deleted.

Binary file not shown.
35 changes: 19 additions & 16 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.cysharp.zstring": "https://github.com/Cysharp/ZString.git?path=src/ZString.Unity/Assets/Scripts/ZString",
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
"com.dotnetg2p.core": "https://github.com/ayutaz/dot-net-g2p.git?path=src/DotNetG2P.Core#5b531c7b0692ec20d892dd0bdfe67a1988059f3b",
"com.dotnetg2p.mecab": "https://github.com/ayutaz/dot-net-g2p.git?path=src/DotNetG2P.MeCab#5b531c7b0692ec20d892dd0bdfe67a1988059f3b",
"com.frozenstorminteractive.assimp.macos": "4.1.0",
"com.frozenstorminteractive.assimp.windows": "4.1.0",
"com.unity.collab-proxy": "2.7.1",
"com.unity.feature.2d": "2.0.1",
"com.unity.formats.fbx": "5.1.2",
"com.unity.ide.rider": "3.0.36",
"com.unity.ide.visualstudio": "2.0.23",
"com.unity.inputsystem": "1.14.0",
"com.unity.localization": "1.5.4",
"com.unity.collab-proxy": "2.11.2",
"com.unity.feature.2d": "2.0.2",
"com.unity.formats.fbx": "5.1.4",
"com.unity.ide.rider": "3.0.38",
"com.unity.ide.visualstudio": "2.0.26",
"com.unity.inputsystem": "1.18.0",
"com.unity.localization": "1.5.8",
"com.unity.logging": "1.3.4",
"com.unity.memoryprofiler": "1.1.6",
"com.unity.multiplayer.center": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.memoryprofiler": "1.1.9",
"com.unity.multiplayer.center": "1.0.1",
"com.unity.nuget.newtonsoft-json": "3.2.2",
"com.unity.playablegraph-visualizer": "0.2.1-preview.3",
"com.unity.recorder": "5.1.2",
"com.unity.render-pipelines.universal": "17.1.0",
"com.unity.test-framework": "1.5.1",
"com.unity.timeline": "1.8.7",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.10",
"com.unity.recorder": "5.1.4",
"com.unity.render-pipelines.universal": "17.3.0",
"com.unity.test-framework": "1.6.0",
"com.unity.timeline": "1.8.10",
"com.unity.ugui": "2.0.0",
"com.unity.visualscripting": "1.9.6",
"com.unity.visualscripting": "1.9.9",
"com.vrmc.gltf": "https://github.com/vrm-c/UniVRM.git?path=/Assets/UniGLTF#v0.128.1",
"com.vrmc.vrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM10#v0.128.1",
"io.github.gkngkc.unity-standalone-file-browser": "https://github.com/shiena/UnityStandaloneFileBrowser.git?path=Packages/StandaloneFileBrowser#upm",
"jp.amagamina.overwriter": "https://github.com/ina-amagami/unity-overwriter.git",
"jp.lilxyzw.liltoon": "https://github.com/lilxyzw/lilToon.git?path=Assets/lilToon#master",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.adaptiveperformance": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand All @@ -60,6 +62,7 @@
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vectorgraphics": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
Expand Down
Loading
Loading