-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTS.cs
37 lines (32 loc) · 1018 Bytes
/
TTS.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
using System.Linq;
using System.Collections.Generic;
using System.Speech.Synthesis;
namespace GameOCRTTS
{
internal static class TTS
{
private static SpeechSynthesizer _TTS = new SpeechSynthesizer();
internal static void SpeakOut(string text)
{
SpeakOut(text, null);
}
internal static void SpeakOut(string text, string voicename)
{
_TTS.Dispose();
if (string.IsNullOrEmpty(text))
return;
_TTS = new SpeechSynthesizer();
_TTS.InjectOneCoreVoices();
if (!string.IsNullOrEmpty(voicename))
_TTS.SelectVoice(voicename);
_TTS.SpeakAsync(text);
}
internal static List<string> GetVoices()
{
_TTS.InjectOneCoreVoices();
var voicelist = _TTS.GetInstalledVoices();
var result = voicelist.Select(x => x.VoiceInfo.Name).ToList();
return result;
}
}
}