Tanoda
VoiceTTS.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.IO;
5using UnityEngine;
6using Debug = UnityEngine.Debug;
7
8public class VoiceTTS : MonoBehaviour
9{
10#if DANA
11 private static string[] languages;
12
13 public static void Initialize()
14 {
15 var startInfo = new ProcessStartInfo()
16 {
17 FileName = Path.Combine(Application.streamingAssetsPath, "UnityTTSHelper.exe"),
18 Arguments = $"-L",
19 CreateNoWindow = true,
20 Verb = "runas"
21 //RedirectStandardOutput = true
22 };
23 /*var process = */Process.Start(startInfo);
24
25
26 }
27
28 public static Process Speak(string text, string language = "hu-HU")
29 {
30 var startInfo = new ProcessStartInfo()
31 {
32 FileName = Path.Combine(Application.streamingAssetsPath, "UnityTTSHelper.exe"),
33 Arguments = $"-l {language} {text}",
34 CreateNoWindow = true,
35 //RedirectStandardOutput = true
36
37 };
38 /*var process = */return Process.Start(startInfo);
39
40
41 }
42
43 public static Process SpeakToFile(string text , string fileName = "output.wav", string language = "hu-HU")
44 {
45 var startInfo = new ProcessStartInfo()
46 {
47 FileName = Path.Combine(Application.streamingAssetsPath, "UnityTTSHelper.exe"),
48 Arguments = $"-l {language} -s {fileName} {text}",
49 CreateNoWindow = true,
50 //RedirectStandardOutput = true
51
52 };
53 /*var process = */
54 return Process.Start(startInfo);
55
56
57 }
58
59 public static string[] InstalledLanguages()
60 {
61 if (languages != null)
62 {
63 return languages;
64 }
65 var startInfo = new ProcessStartInfo()
66 {
67 FileName = Path.Combine(Application.streamingAssetsPath, "UnityTTSHelper.exe"),
68 Arguments = $"-L",
69 CreateNoWindow = true,
70 RedirectStandardOutput = true,
71 RedirectStandardError = true,
72 UseShellExecute = false,
73 };
74 var process = Process.Start(startInfo);
75 process.WaitForExit(2500);
76 var stdout = process.StandardOutput.ReadToEnd();
77 var stderr = process.StandardError.ReadToEnd();
78
79 if (string.IsNullOrEmpty(stderr))
80 Debug.LogError(stderr);
81
82 if (string.IsNullOrEmpty(stdout))
83 {
84 return new string[0];
85 }
86 if (stdout.Contains(";"))
87 {
88 languages = stdout.Split(';');
89 return languages;
90 }
91
92 languages = new[] {stdout};
93 return languages;
94 }
95#endif
96}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19