-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
165 lines (136 loc) · 5.46 KB
/
MainWindow.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
using NAudio.Wave;
using OpenAI.Audio;
using System.Windows.Forms;
// you know adding comments is one of my favorite things to do
// because i know no one will read them
namespace Bluebird_TTS;
public partial class MainWindow : Form
{
public bool StopRecord = false;
private Button _record = new Button();
private Button _stop = new Button();
private Button _transcribe = new Button();
private Button _savelocation = new Button();
private Button _copy = new Button();
//adding a output text block place for easy viewing
private TextBox _textblock = new TextBox();
public string SavePath;
public string TranscribedText;
public MainWindow() //Regretting doing this in WinForms...
{
InitializeComponent();
this.Text = "Blackbird TTS";
this.TopMost = true;
BackColor = Color.White;
Font = new Font("Arial", 12);
InitializeAllThingys();
}
private void InitializeAllThingys() //So what if i can't name things for shit? its not like people read this
{
_record.DialogResult = DialogResult.OK;
_stop.DialogResult = DialogResult.OK;
_transcribe.DialogResult = DialogResult.OK;
_savelocation.DialogResult = DialogResult.OK;
_copy.DialogResult = DialogResult.OK;
_record.Text = "Record";
_stop.Text = "Stop";
_transcribe.Text = "Transcribe";
_textblock.Text = "Placeholder";
_savelocation.Text = "Save";
_copy.Text = "Copy";
_record.Size = new System.Drawing.Size(124, 50);
_stop.Size = new Size(124, 50);
_transcribe.Size = new Size(124, 50);
//_textblock.Size = new Size(300, 100);
_savelocation.Size = new Size(124, 50);
_copy.Size = new Size(124, 50);
_textblock.ReadOnly = true;
_stop.Location = new System.Drawing.Point(0, 62);
_transcribe.Location = new Point(0, 124);
_savelocation.Location = new Point(0, 204);
_copy.Location = new Point(0, 266);
_textblock.Location = new Point (200, 1);
_record.Click += new EventHandler(Record_method);
_stop.Click += new EventHandler(Stop_method);
_transcribe.Click += new EventHandler(Transcribe_method);
_savelocation.Click += new EventHandler(Save_method);
_copy.Click += new EventHandler(Copy_method);
_stop.Enabled = false;
_transcribe.Enabled = false;
//_savelocation.Enabled = false;
_textblock.BorderStyle = BorderStyle.FixedSingle;
_textblock.Dock = DockStyle.Fill;
_textblock.BackColor = Color.WhiteSmoke;
_textblock.Font = new Font("Arial", 12);
// Create and configure the layout panel
Controls.Add(_record);
Controls.Add(_stop);
Controls.Add(_transcribe);// naww look at how neat and boiler plate it is
// Controls.Add(_textblock);
Controls.Add(_savelocation);
Controls.Add(_copy);
}
private void Copy_method(object? sender, EventArgs e)
{
Clipboard.SetText(TranscribedText);
}
private void Save_method(object? sender, EventArgs e)
{
SaveFileDialog Save_location = new SaveFileDialog();
Save_location.Title = "Where to Save Transcription";
Save_location.InitialDirectory = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Save_location.DefaultExt = "txt";
Save_location.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
//Saving the path to a variable
SavePath = Save_location.FileName;
Save_location.ShowDialog();
// Writing the transcription to the file
File.WriteAllText(SavePath, TranscribedText);
}
private void Stop_method(object? sender, EventArgs e)
{
StopRecord = true;
_record.Enabled = true;
_stop.Enabled = false;
_transcribe.Enabled = true;
// there has got to be a better way to do this
}
private async void Transcribe_method(object? sender, EventArgs e)
{
string Transcription_request = await Variable.AiClient.AudioEndpoint.CreateTranscriptionAsync(new AudioTranscriptionRequest(Path.GetFullPath(Variable.OutputFilePath), language: "en"));
MessageBox.Show(Transcription_request);
TranscribedText = Transcription_request;
}
private void Record_method(object? sender, EventArgs e)
{
try
{
_record.Enabled = false;
_stop.Enabled = true;
StopRecord = false;
WaveInEvent Wave_in = new WaveInEvent();
WaveFileWriter Writer = new WaveFileWriter(Variable.OutputFilePath, Wave_in.WaveFormat);
Wave_in.StartRecording();
Wave_in.DataAvailable += (s, a) =>
{
//Boolean plsStop = ;
Writer.Write(a.Buffer, 0, a.BytesRecorded);
if (StopRecord)
{
Wave_in.StopRecording();
Wave_in.Dispose();
Writer.Dispose();
}
};
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
protected override void OnFormClosing(FormClosingEventArgs e) {
e.Cancel = false;
base.OnFormClosing(e);
// stackoverflow told me to do this and if stackoverflow told me to do it... i would have killed myself but thats not the point
}
}