-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathForm1.cs
230 lines (215 loc) · 10.5 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32; // it's required for reading and writing to the windows registry
namespace SAPI_Unifier
{
public partial class Form_main : Form
{
public Form_main()
{
InitializeComponent();
//MessageBox.Show("Program is Running!"); // to check validity of single instance running. It's work fine :) Thanks https://www.c-sharpcorner.com/UploadFile/f9f215/how-to-restrict-the-application-to-just-one-instance/
string SAPI5Path = "SOFTWARE\\Microsoft\\SPEECH\\Voices\\Tokens\\";
string MobilePath = "SOFTWARE\\Microsoft\\Speech_OneCore\\Voices\\Tokens\\";
string ServerPath = "SOFTWARE\\Microsoft\\Speech Server\\v11.0\\Voices\\Tokens\\";
string CortanaPath = "SOFTWARE\\Microsoft\\Speech_OneCore\\CortanaVoices\\Tokens\\";
if (System.Environment.Is64BitOperatingSystem)
{
SAPI5Path = "SOFTWARE\\WOW6432Node\\Microsoft\\SPEECH\\Voices\\Tokens\\";
MobilePath = "SOFTWARE\\WOW6432Node\\Microsoft\\Speech_OneCore\\Voices\\Tokens\\";
ServerPath = "SOFTWARE\\WOW6432Node\\Microsoft\\Speech Server\\v11.0\\Voices\\Tokens\\";
}
string[] SAPI5Tokens = new string[] { };
string[] MobileTokens = new string[] { };
string[] ServerTokens = new string[] { };
string[] CortanaTokens = new string[] { };
try
{
//// Fix possible inconsistencies in SAPI 5 voices due to some uninstalled mobile or server voices
RegistryKey key = Registry.LocalMachine.OpenSubKey(SAPI5Path);
if (key != null) SAPI5Tokens = key.GetSubKeyNames();
key = Registry.LocalMachine.OpenSubKey(MobilePath);
if (key != null) MobileTokens = key.GetSubKeyNames();
key = Registry.LocalMachine.OpenSubKey(ServerPath);
if (key != null) ServerTokens = key.GetSubKeyNames();
key = Registry.LocalMachine.OpenSubKey(CortanaPath);
if (key != null) CortanaTokens = key.GetSubKeyNames();
//MessageBox.Show(MobileTokens.Length.ToString(),"Number of instaled Mobile Tokens", MessageBoxButtons.OK, MessageBoxIcon.Information);
//MessageBox.Show(ServerTokens.Length.ToString(),"Number of instaled Server Tokens", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("An Error in the preliminary analysis is occurred!", "Error #1", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
foreach (string SAPI5Token in SAPI5Tokens)
{
//MessageBox.Show(SAPI5Token);
//MessageBox.Show(Array.IndexOf(MobileTokens, SAPI5Token).ToString());
try
{
// Remove uninstalled oneCore voices from the SAPI 5 interface
if (SAPI5Token.Contains("MSTTS_V110_"))
{
if (Array.IndexOf(MobileTokens, SAPI5Token) < 0 & Array.IndexOf(CortanaTokens, SAPI5Token) < 0)
{
//MessageBox.Show(SAPI5Token);
RegistryKey key = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + SAPI5Token);
string VoiceName = key.GetValue("").ToString();
textBox_report.Text = VoiceName + " which was an uninstalled OneCore voice is removed from SAPI 5." + Environment.NewLine;
key = Registry.LocalMachine.OpenSubKey(SAPI5Path, true); // request write permission
key.DeleteSubKeyTree(SAPI5Token, false); // do not raise an error if the subkey be missing
}
}
}
catch
{
MessageBox.Show("An Error in removing of " + SAPI5Token + " is occurred!", "Error #2", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
// Remove uninstalled SpeechServer voices from the SAPI 5 interface
if (SAPI5Token.Contains("TTS_MS_"))
{
if (Array.IndexOf(ServerTokens, SAPI5Token) < 0)
{
//MessageBox.Show(SAPI5Token);
RegistryKey key = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + SAPI5Token);
string VoiceName = key.GetValue("").ToString();
if (VoiceName.Contains("Microsoft Server Speech Text to Speech Voice"))
{
textBox_report.Text = VoiceName + " which was an uninstalled Speech Server voice is removed from SAPI 5." + Environment.NewLine;
key = Registry.LocalMachine.OpenSubKey(SAPI5Path, true);
key.DeleteSubKeyTree(SAPI5Token, false);
}
}
}
}
catch
{
MessageBox.Show("An Error in removing of " + SAPI5Token + " is occurred!", "Error #3", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//// Now that all things become OK it's time to add OneCore voices to SAPI 5 interface
foreach (string MobileToken in MobileTokens)
{
try
{
if (Array.IndexOf(SAPI5Tokens, MobileToken) < 0)
{
//MessageBox.Show(MobileToken);
// Create a SAPI5Token with the same name of the MobileToken
RegistryKey dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path, true);
dstkey.CreateSubKey(MobileToken);
// Copy values from the MobileToken to the created SAPI5Token
RegistryKey srckey = Registry.LocalMachine.OpenSubKey(MobilePath + "\\" + MobileToken);
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + MobileToken, true);
foreach (string name in srckey.GetValueNames())
{
//MessageBox.Show(name);
if (name == "")
{
textBox_report.Text = textBox_report.Text + srckey.GetValue(name) + " is added from OneCore Speech API to SAPI 5." + Environment.NewLine;
}
dstkey.SetValue(name, srckey.GetValue(name), srckey.GetValueKind(name));
}
// Create the Attributes subkey for the created voice Token
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + MobileToken, true);
dstkey.CreateSubKey("Attributes");
// Copy values from the Attributes subkey of the MobileToken to the created Attributes subkey of SAPI5Token
srckey = Registry.LocalMachine.OpenSubKey(MobilePath + "\\" + MobileToken + "\\" + "Attributes");
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + MobileToken + "\\" + "Attributes", true);
foreach (string name in srckey.GetValueNames())
{
dstkey.SetValue(name, srckey.GetValue(name), srckey.GetValueKind(name));
}
}
}
catch
{
MessageBox.Show("An Error in adding of " + MobileToken + " is occurred!", "Error #4", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//// Now that all things become OK it's time to add SpeechServer voices to SAPI 5 interface
foreach (string ServerToken in ServerTokens)
{
try
{
if (Array.IndexOf(SAPI5Tokens, ServerToken) < 0)
{
//MessageBox.Show(MobileToken);
// Create a SAPI5Token with the same name of the MobileToken
RegistryKey dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path, true);
dstkey.CreateSubKey(ServerToken);
// Copy values from the MobileToken to the created SAPI5Token
RegistryKey srckey = Registry.LocalMachine.OpenSubKey(ServerPath + "\\" + ServerToken);
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + ServerToken, true);
foreach (string name in srckey.GetValueNames())
{
//MessageBox.Show(name);
if (name == "")
{
textBox_report.Text = textBox_report.Text + srckey.GetValue(name) + " is added from Speech Server Speech API to SAPI 5." + Environment.NewLine;
}
dstkey.SetValue(name, srckey.GetValue(name), srckey.GetValueKind(name));
}
// Create the Attributes subkey for the created voice Token
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + ServerToken, true);
dstkey.CreateSubKey("Attributes");
// Copy values from the Attributes subkey of the MobileToken to the created Attributes subkey of SAPI5Token
srckey = Registry.LocalMachine.OpenSubKey(ServerPath + "\\" + ServerToken + "\\" + "Attributes");
dstkey = Registry.LocalMachine.OpenSubKey(SAPI5Path + "\\" + ServerToken + "\\" + "Attributes", true);
foreach (string name in srckey.GetValueNames())
{
dstkey.SetValue(name, srckey.GetValue(name), srckey.GetValueKind(name));
}
}
}
catch
{
MessageBox.Show("An Error in adding of " + ServerToken + " is occurred!", "Error #5", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// if there is no installed Mobile voice (which occurs in all Windows except Windows 10) and no Server voice then I suggest installing some server voices
if (MobileTokens.Length == 0 & ServerTokens.Length == 0)
{
textBox_report.Text = textBox_report.Text + "I could not find any unifiable voice on your system. So, I suggest installing the Microsoft Speech Platform (Speech Server) Runtime version 11 x86 and some of its supported voices." + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "The x86 version of Microsoft Speech Platform 11 can be installed on both x86 and x64 versions of Windows XP, Vista, 7, 8, 8.1, and 10." + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "See the below link for installing x86_SpeechPlatformRuntime:" + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "https://www.microsoft.com/en-us/download/details.aspx?id=27225" + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "See the below link for installing some voices which are titled MSSpeech_TTS:" + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "https://www.microsoft.com/en-us/download/details.aspx?id=27224" + Environment.NewLine;
textBox_report.Text = textBox_report.Text + "Note: for example, MSSpeech_TTS_en-US_Helen.msi and MSSpeech_TTS_en-US_ZiraPro.msi are two installable English (US) voices." + Environment.NewLine;
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (textBox_report.Text == "")
{
textBox_report.Text = "It seems everything is OK. Please don't forget to re-run the SAPI Unifier after installing or uninstalling of any OneCore or Speech Server voices.";
}
}
private void button_exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_about_Click(object sender, EventArgs e)
{
MessageBox.Show("Author: Mahmood Taghavi; Version 1.1; License: GPL 3", "About SAPI Unifier", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void linkLabel_website_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Change the color of the link text by setting LinkVisited
// to true.
linkLabel_website.LinkVisited = true;
//Call the Process.Start method to open the default browser
//with a URL:
System.Diagnostics.Process.Start("https://mahmood-taghavi.github.io/SAPI_Unifier/");
}
}
}