-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm2.cs
More file actions
53 lines (50 loc) · 2.23 KB
/
Form2.cs
File metadata and controls
53 lines (50 loc) · 2.23 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
using Microsoft.CognitiveServices.Speech;
using NeuroTTS.Properties;
using System;
using System.Windows.Forms;
namespace NeuroTTS
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = Settings.Default.REGION;
textBox2.Text = Settings.Default.API_KEY;
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text))
{
MessageBox.Show("Please fill in both fields!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string ssml = "<speak version='1.0' xml:lang='en-US'><voice name='en-US-AshleyNeural'><express-as style='chat'><prosody pitch='+25%'>Hello! I'm Neuro. Someone tell vedal there is a problem with my AI.</prosody></express-as></voice></speak>";
SpeechConfig speechConfig = SpeechConfig.FromSubscription(textBox2.Text, textBox1.Text);
button1.Enabled = false;
using (SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(speechConfig))
{
SpeechSynthesisResult result = speechSynthesizer.SpeakSsmlAsync(ssml).Result;
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
button1.Enabled = true;
MessageBox.Show("Test successful!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
Settings.Default.REGION = textBox1.Text;
Settings.Default.API_KEY = textBox2.Text;
Settings.Default.Save();
// MessageBox.Show("Setup complete!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
button1.Enabled = true;
MessageBox.Show("Test failed: " + result.Reason.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
}