-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmMain.cs
More file actions
68 lines (54 loc) · 1.8 KB
/
frmMain.cs
File metadata and controls
68 lines (54 loc) · 1.8 KB
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
using System;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.IO;
namespace TextToSpeech
{
public partial class frmMain : Form
{
SpeechSynthesizer _voice;
public frmMain()
{
InitializeComponent();
_voice = new SpeechSynthesizer();
cboSelectVoice.DataSource = Enum.GetValues(typeof(VoiceGender));
}
private void Speak_Click(object sender, EventArgs e)
{
_voice.SelectVoiceByHints((VoiceGender)cboSelectVoice.SelectedItem);
if (!string.IsNullOrEmpty(txtContent.Text))
_voice.SpeakAsync(txtContent.Text);
}
private void Save_Click(object sender, EventArgs e)
{
using (SaveFileDialog sfd = new SaveFileDialog()
{
Filter = "Wav Files|*.wav",
Title = "Save File as Wav"
})
{
if (sfd.ShowDialog() != DialogResult.OK)
return;
try
{
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
{
_voice.SetOutputToWaveStream(fs);
_voice.Speak(txtContent.Text);
}
}
catch (Exception ex)
{
//handle here
}
}
}
private void Pause_Click(object sender, EventArgs e) =>
_voice.Pause();
private void Resume_Click(object sender, EventArgs e) =>
_voice.Resume();
private void frmMain_Load(object sender, EventArgs e)
{
}
}
}