-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
130 lines (113 loc) · 3.78 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ttsapp
{
public partial class Form1 : Form
{
private SpeechSynthesizer _synthesizer;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
this._synthesizer = new SpeechSynthesizer();
this._synthesizer.Volume = Volume_TrackBar.Value;
this._synthesizer.Rate = Rate_TrackBar.Value;
foreach (var voice in this._synthesizer.GetInstalledVoices())
{
if (voice.Enabled)
{
Voice_ComboBox.Items.Add(voice.VoiceInfo.Name);
}
}
Voice_ComboBox.SelectedIndex = 0;
this._synthesizer.SelectVoice(Voice_ComboBox.SelectedItem.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Failed to initialize speech synthesizer: " + ex.Message + "\r\n\r\n" + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return;
}
}
private void QR_Yes_Button_Click(object sender, EventArgs e)
{
string text = "";
if (sender == QR_Dunno_Button)
{
text = "I don't know.";
}
else if (sender == QR_ExplainVoice_Button)
{
text = "For medical reasons I cannot speak for the time being, so I am using this computer assisted speech program to communicate.";
}
else if (sender == QR_Look_Button)
{
text = "Look here.";
}
else if (sender == QR_No_button)
{
text = "No";
}
else if (sender == QR_ThankYou_Button)
{
text = "Thank you.";
}
else if (sender == QR_Yes_Button)
{
text = "Yes";
}
Text_TextBox.Text = text;
if (Speak_Button.Enabled)
{
Speak_Button.PerformClick();
}
Text_TextBox.SelectionStart = 0;
Text_TextBox.SelectionLength = 0;
Text_TextBox.SelectAll();
}
private void Text_TextBox_TextChanged(object sender, EventArgs e)
{
Speak_Button.Enabled = (Text_TextBox.Text.Trim().Length > 0);
}
private void Speak_Button_Click(object sender, EventArgs e)
{
_synthesizer.SpeakAsyncCancelAll();
_synthesizer.SpeakAsync(Text_TextBox.Text);
Text_TextBox.SelectionStart = 0;
Text_TextBox.SelectionLength = 0;
Text_TextBox.SelectAll();
}
private void Clear_Button_Click(object sender, EventArgs e)
{
Text_TextBox.Clear();
}
private void Rate_TrackBar_Scroll(object sender, EventArgs e)
{
this._synthesizer.Rate = Rate_TrackBar.Value;
}
private void Volume_TrackBar_Scroll(object sender, EventArgs e)
{
this._synthesizer.Volume = Volume_TrackBar.Value;
}
private void Voice_ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
this._synthesizer.SelectVoice(Voice_ComboBox.SelectedItem.ToString());
}
private void Quit_Button_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}