A plug-in for using OpenJTalk on Unity.
It allows you to read out text dynamically.
- ReadMe(English)
- ReadMe(日本語)
The code is developed on following environments. Note that these are NOT minimum version requirements.
- Windows 10 20H2
- Unity Editor 2020.3.12f1 (LTS)
- Import OpenJTalkForUnity.unitypackage to your project
- Set "Edit > Project Settings > Other Settings > Configuration > Api Compatibility Level" to ".NET 4.x"
- Write the program. Refer to
Assets\OpenJTalkForUnity\Scene
.
In "Window>Package Manager", select "Add package from git URL...". Then type https://github.com/rarafy/OpenJTalkForUnity.git?path=_Project/Packages/OpenJTalkForUnity
and press "Add".
Let's also import the sample program. The sample programs will be placed in Assets/Samples/OpenJTalkForUnity/1.1.13/Sample
.
There are several APIs available. Basically, you should refer to Assets\OpenJTalkForUnity\Scene
to write scripts.
OpenJTalk.VoiceTypeInfo()
:Check which voices are available and output as Debug.Log.OpenJTalk.SpeakRandomVoice(string text, double speed=1.0)
:Speaks in a random voice.OpenJTalk.Speak(string text = "Hello", string VoiceName = "tohoku-f01-neutral", double speed = 1.0)
:Reads out an arbitrary string of text at a specified voice and speed.OpenJTalk.SpeakRandomVoiceStoppable(string text = "Hello", double speed = 1.0)
:It speaks in a random voice. (It's a Task, so it's asynchronous.)OpenJTalk.SpeakStoppable(string text = "Hello", string VoiceName = "tohoku-f01-neutral", double speed = 1.0)
:Reads out an arbitrary string of text at a specified voice and speed.OpenJTalk.StopSpeaking()
:Stop vocalizing midway.
- I'm getting a mysterious error.
It seems to be a problem with the unmanaged DLL. It does not interfere with actual use.
If you are really concerned about this, you can delete the corresponding file (some advanced features will not be available).
- I want to use a different voice.
You can use any htsvoice that is placed in the hierarchy below Assets\OpenJTalkForUnity\dll\voice by specifying its name as the second argument of Speak().
Ex:When you want to use "takumi_happy.htsvoice"
void Start(){ OpenJTalkForUnity.Speak("Today is a nice day.", "takumi_happy"); }
- My app stops while reading out loud.
A feature called Asynchronous (Task) can be used to solve this problem. For example
void Start()
{
Task.Run(() => OpenJTalk.Speak("Today is a nice day."));
}
↑ Using tasks in this way will prevent the application from stopping while it is running.
- Um, OpenJTalk, I think there were more parameters? (Advanced)
You can unlock those parameters by editing Assets\OpenJTalkForUnity\Scripts\OpenJTalk.cs
.
For example, if you want to add a Speed parameter, you can add tts.Speed = 1.0;
to the line before tts.SpeakAsync(text);
.
Of course, you can also rewrite the first part of the declaration as
JTalkTTS tts = new JTalkTTS { VoiceName = "tohoku-f01-neutral", Speed = 1.0 }
.