Skip to content

Commit

Permalink
インストールが不要な形に変更・APIの中身を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
rarafy committed Aug 29, 2021
1 parent 07c8118 commit fed8bcd
Show file tree
Hide file tree
Showing 100 changed files with 4,149 additions and 122 deletions.
Binary file modified OpenJTalkForUnity.unitypackage
Binary file not shown.
116 changes: 116 additions & 0 deletions _Project/Assets/OpenJTalkForUnity/Scripts/OpenJTalk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using JTalkDll;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using UnityEngine;

public class OpenJTalk
{
// 参照-------------------------------------------------------------------------------------------------------------------
private static JTalkTTS _tts = new JTalkTTS { VoiceName = "tohoku-f01-neutral" };
/// <summary>
/// インストールされている全てのボイスの種類を表示します。<br/><br/>
/// ※ボイスは"Assets\OpenJTalkForUnity\dll\voice"に格納されているものを探しに行きます。
/// </summary>
public static void VoiceTypeInfo()
{
List<string> a = new List<string>();
a.AddRange(_tts.Voices.Select(v => v.Name).ToList<string>());

foreach (string item in a) Debug.Log(item);
}


// 発声(同期)-------------------------------------------------------------------------------------------------------------------

/// <summary>
/// ランダムな声で喋ります。引数にstringで喋らせたい文字列を与えてください。
/// </summary>
/// <param name="text">喋らせたい文字列</param>
/// <param name="speed">読み上げ速度</param>
public static void SpeakRandomVoice(string text, double speed = 1.0)
{
using (JTalkTTS tts = new JTalkTTS { })
{
tts.Voice = tts.Voices[new System.Random().Next(tts.Voices.Count)];//Voiceを設定
tts.Speed = speed;//読み上げ速度を設定
tts.SpeakAsync(text);
tts.WaitUntilDone();
}
}

/// <summary>
/// 任意のボイスで喋ります。引数に喋らせたい文字列とボイスの名前(tohoku-f01-neutral)を与えてください。<br />
/// 何も指定しない場合は"tohoku-f01-neutral"の声で「こんにちは」と話します<br /><br />
/// ※ボイスは"Assets\OpenJTalkForUnity\dll\voice"に格納されている必要があります。
/// </summary>
/// <param name="text">喋らせたい文字列</param>
/// <param name="VoiceName">ボイスの名前</param>
/// <param name="speed">読み上げ速度</param>
public static void Speak(string text = "こんにちは", string VoiceName = "tohoku-f01-neutral", double speed = 1.0)
{
using (JTalkTTS tts = new JTalkTTS { VoiceName = VoiceName })
{
tts.Speed = speed;//読み上げ速度を設定
tts.SpeakAsync(text);
tts.WaitUntilDone();
}
}


// 発声(非同期)-------------------------------------------------------------------------------------------------------------------

private static JTalkTTS tts;
private static CancellationTokenSource cancelToken;
/// <summary>
/// ランダムな声で喋ります。引数にstringで喋らせたい文字列を与えてください。
/// 特別な事情が無ければSpeakRandomVoice()よりもこちらを使うのが良いでしょう。
/// </summary>
/// <param name="text">喋らせたい文字列</param>
/// <param name="speed">読み上げ速度</param>
public static Task SpeakRandomVoiceStoppable(string text = "こんにちは", double speed = 1.0)
{
tts = new JTalkTTS { };
tts.Voice = tts.Voices[new System.Random().Next(tts.Voices.Count)];//Voiceを設定
tts.Speed = speed;//読み上げ速度を設定
tts.SpeakAsync(text);

cancelToken = new CancellationTokenSource();
while (tts.IsSpeaking) cancelToken.Token.ThrowIfCancellationRequested();
return null;
}
/// <summary>
/// 何も指定しない場合は「こんにちは」と話します。<br/>
/// 特別な事情が無ければSpeak()よりもこちらを使うのが良いでしょう。<br/><br/>
/// ※ボイスはProjectの"Assets\OpenJTalkForUnity\dll\voice"に格納されていることが前提です
/// </summary>
/// <param name="text">喋らせたい文字列</param>
/// <param name="VoiceName">ボイスの名前</param>
/// <param name="speed">読み上げ速度</param>
public static Task SpeakStoppable(string text = "こんにちは", string VoiceName = "tohoku-f01-neutral", double speed = 1.0)
{
tts = new JTalkTTS { VoiceName = VoiceName };
tts.Speed = speed;//読み上げ速度を設定
tts.SpeakAsync(text);

cancelToken = new CancellationTokenSource();
while (tts.IsSpeaking) cancelToken.Token.ThrowIfCancellationRequested();
return null;
}
/// <summary>
/// 発声を停止します。
/// </summary>
public static void StopSpeaking()
{
if (cancelToken != null) cancelToken.Cancel();
if (tts.IsSpeaking) tts.Stop();
}
}
76 changes: 0 additions & 76 deletions _Project/Assets/OpenJTalkForUnity/Scripts/OpenJTalkForUnity.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class Speak : MonoBehaviour

void Start()
{
OpenJTalkForUnity.Speak(text);
OpenJTalk.Speak(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

public class SpeakRandomVoice : MonoBehaviour
{
[Header("実行するたびに声が変わります")]
[SerializeField] string text = "おはようございます。今日は良い天気ですね。";

void Start()
{
OpenJTalkForUnity.SpeakRandomVoice(text);
OpenJTalk.SpeakRandomVoice(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class SpeakVoiceSelected : MonoBehaviour

void Start()
{
OpenJTalkForUnity.Speak(text, voiceName);
OpenJTalk.Speak(text, voiceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -152,7 +152,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 18dc32cc7f5afbe4e8140b343589d994, type: 3}
m_Name:
m_EditorClassIdentifier:
text: "\u3058\u3085\u3052\u3080\u3058\u3085\u3052\u3080\u3054\u3053\u3046\u306E\u3059\u308A\u304D\u308C\u304B\u3044\u3058\u3083\u308A\u3059\u3044\u304E\u3087\u306E\u3059\u3044\u304E\u3087\u3046\u307E\u3064\u3046\u3093\u3089\u3044\u307E\u3064\u3075\u3046\u3089\u3044\u307E\u3064\u304F\u3046\u306D\u308B\u3068\u3053\u308D\u306B\u3059\u3080\u3068\u3053\u308D\u3084\u3076\u3089\u3053\u3046\u3058\u306E\u3076\u3089\u3053\u3046\u3058\u30D1\u30A4\u30DD\u30D1\u30A4\u30DD\u30D1\u30A4\u30DD\u306E\u30B7\u30E5\u30FC\u30EA\u30F3\u30AC\u30F3\u30B7\u30E5\u30FC\u30EA\u30F3\u30AC\u30F3\u306E\u30B0\u30FC\u30EA\u30F3\u30C0\u30A4\u30B0\u30FC\u30EA\u30F3\u30C0\u30A4\u306E\u30DD\u30F3\u30DD\u30B3\u30D4\u30FC\u306E\u30DD\u30F3\u30DD\u30B3\u30CA\u306E\u3061\u3087\u3046\u304D\u3085\u3046\u3081\u3044\u306E\u3061\u3087\u3046\u3059\u3051"
text: "\u660E\u65E5\u5929\u6C17\u306B\u306A\u30FC\u308C"
voiceName: tohoku-f01-sad
--- !u!4 &44975081
Transform:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public void StartSpeaking()
{
Task task = Task.Run(() =>
{
return OpenJTalkForUnity.SpeakStoppable(text, voiceName);
return OpenJTalk.SpeakStoppable(text, voiceName);
});
}

public void Stop()
{
OpenJTalkForUnity.StopSpeaking();
OpenJTalk.StopSpeaking();
}
}
12 changes: 12 additions & 0 deletions _Project/Assets/OpenJTalkForUnity/_Scene/VoiceTypeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class VoiceTypeInfo : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
OpenJTalk.VoiceTypeInfo();
}
}
11 changes: 11 additions & 0 deletions _Project/Assets/OpenJTalkForUnity/_Scene/VoiceTypeInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fed8bcd

Please sign in to comment.