|
@@ -8,9 +8,11 @@ using NAudio.Wave;
|
8
|
8
|
using System;
|
9
|
9
|
using System.Collections.Generic;
|
10
|
10
|
using System.Data;
|
|
11
|
+using System.Diagnostics;
|
11
|
12
|
using System.Drawing.Imaging;
|
12
|
13
|
using System.IO;
|
13
|
14
|
using System.Threading;
|
|
15
|
+using System.Threading.Tasks;
|
14
|
16
|
using System.Windows;
|
15
|
17
|
using System.Windows.Input;
|
16
|
18
|
using System.Windows.Media.Imaging;
|
|
@@ -32,9 +34,16 @@ namespace XHWK.WKTool
|
32
|
34
|
{
|
33
|
35
|
InitializeComponent();
|
34
|
36
|
|
|
37
|
+ MicrophoneSetting.Click += MicrophoneSetting_Click;
|
|
38
|
+
|
35
|
39
|
cameraCheck();
|
36
|
40
|
}
|
37
|
41
|
|
|
42
|
+ private void MicrophoneSetting_Click(object sender, RoutedEventArgs e)
|
|
43
|
+ {
|
|
44
|
+ Process.Start("mmsys.cpl");
|
|
45
|
+ }
|
|
46
|
+
|
38
|
47
|
/// <summary>
|
39
|
48
|
/// 初始化
|
40
|
49
|
/// </summary>
|
|
@@ -48,8 +57,10 @@ namespace XHWK.WKTool
|
48
|
57
|
/// <summary>
|
49
|
58
|
/// 窗体移动
|
50
|
59
|
/// </summary>
|
51
|
|
- /// <param name="sender"></param>
|
52
|
|
- /// <param name="e"></param>
|
|
60
|
+ /// <param name="sender">
|
|
61
|
+ /// </param>
|
|
62
|
+ /// <param name="e">
|
|
63
|
+ /// </param>
|
53
|
64
|
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
54
|
65
|
{
|
55
|
66
|
DragMove();
|
|
@@ -58,8 +69,10 @@ namespace XHWK.WKTool
|
58
|
69
|
/// <summary>
|
59
|
70
|
/// 关闭当前页
|
60
|
71
|
/// </summary>
|
61
|
|
- /// <param name="sender"></param>
|
62
|
|
- /// <param name="e"></param>
|
|
72
|
+ /// <param name="sender">
|
|
73
|
+ /// </param>
|
|
74
|
+ /// <param name="e">
|
|
75
|
+ /// </param>
|
63
|
76
|
private void BtnDown_Click(object sender, RoutedEventArgs e)
|
64
|
77
|
{
|
65
|
78
|
imgPlayer.Visibility = Visibility.Hidden;
|
|
@@ -98,8 +111,10 @@ namespace XHWK.WKTool
|
98
|
111
|
/// <summary>
|
99
|
112
|
/// 检测
|
100
|
113
|
/// </summary>
|
101
|
|
- /// <param name="sender"></param>
|
102
|
|
- /// <param name="e"></param>
|
|
114
|
+ /// <param name="sender">
|
|
115
|
+ /// </param>
|
|
116
|
+ /// <param name="e">
|
|
117
|
+ /// </param>
|
103
|
118
|
private void checkCamera()
|
104
|
119
|
{
|
105
|
120
|
try
|
|
@@ -159,8 +174,10 @@ namespace XHWK.WKTool
|
159
|
174
|
/// <summary>
|
160
|
175
|
/// 停止
|
161
|
176
|
/// </summary>
|
162
|
|
- /// <param name="sender"></param>
|
163
|
|
- /// <param name="e"></param>
|
|
177
|
+ /// <param name="sender">
|
|
178
|
+ /// </param>
|
|
179
|
+ /// <param name="e">
|
|
180
|
+ /// </param>
|
164
|
181
|
private void BtnCameraStop_Click(object sender, RoutedEventArgs e)
|
165
|
182
|
{
|
166
|
183
|
if (Camera != null)
|
|
@@ -176,8 +193,10 @@ namespace XHWK.WKTool
|
176
|
193
|
/// <summary>
|
177
|
194
|
/// 扬声器
|
178
|
195
|
/// </summary>
|
179
|
|
- /// <param name="sender"></param>
|
180
|
|
- /// <param name="e"></param>
|
|
196
|
+ /// <param name="sender">
|
|
197
|
+ /// </param>
|
|
198
|
+ /// <param name="e">
|
|
199
|
+ /// </param>
|
181
|
200
|
private void Speaker_Check()
|
182
|
201
|
{
|
183
|
202
|
closeCamera();
|
|
@@ -189,8 +208,10 @@ namespace XHWK.WKTool
|
189
|
208
|
/// <summary>
|
190
|
209
|
/// 检测扬声器
|
191
|
210
|
/// </summary>
|
192
|
|
- /// <param name="sender"></param>
|
193
|
|
- /// <param name="e"></param>
|
|
211
|
+ /// <param name="sender">
|
|
212
|
+ /// </param>
|
|
213
|
+ /// <param name="e">
|
|
214
|
+ /// </param>
|
194
|
215
|
private void BtnSpeakerDetection_Click(object sender, RoutedEventArgs e)
|
195
|
216
|
{
|
196
|
217
|
Console.WriteLine("播放");
|
|
@@ -205,8 +226,10 @@ namespace XHWK.WKTool
|
205
|
226
|
/// <summary>
|
206
|
227
|
/// 音频播放 同步进度条和视频进度
|
207
|
228
|
/// </summary>
|
208
|
|
- /// <param name="sender"></param>
|
209
|
|
- /// <param name="e"></param>
|
|
229
|
+ /// <param name="sender">
|
|
230
|
+ /// </param>
|
|
231
|
+ /// <param name="e">
|
|
232
|
+ /// </param>
|
210
|
233
|
private void MediaAudio_MediaOpened(object sender, RoutedEventArgs e)
|
211
|
234
|
{
|
212
|
235
|
Console.WriteLine("播放中。。。");
|
|
@@ -227,20 +250,21 @@ namespace XHWK.WKTool
|
227
|
250
|
/// <summary>
|
228
|
251
|
/// 麦克风
|
229
|
252
|
/// </summary>
|
230
|
|
- /// <param name="sender"></param>
|
231
|
|
- /// <param name="e"></param>
|
232
|
|
- private void Microphone_Check()
|
|
253
|
+ /// <param name="sender">
|
|
254
|
+ /// </param>
|
|
255
|
+ /// <param name="e">
|
|
256
|
+ /// </param>
|
|
257
|
+ private async void Microphone_Check()
|
233
|
258
|
{
|
234
|
259
|
MediaAudio.Stop();
|
235
|
260
|
ImgAcousticWave.Visibility = Visibility.Collapsed;
|
236
|
261
|
HidePage();
|
237
|
262
|
GridMicrophone.Visibility = Visibility.Visible;
|
238
|
|
-
|
239
|
|
- ThreadPool.QueueUserWorkItem(s =>
|
|
263
|
+ DataTable data = new DataTable();
|
|
264
|
+ data.Columns.Add("Value");
|
|
265
|
+ data.Columns.Add("Key");
|
|
266
|
+ await Task.Run(() =>
|
240
|
267
|
{
|
241
|
|
- DataTable data = new DataTable();
|
242
|
|
- data.Columns.Add("Value");
|
243
|
|
- data.Columns.Add("Key");
|
244
|
268
|
for (int n = 0; n < WaveIn.DeviceCount; n++)
|
245
|
269
|
{
|
246
|
270
|
var caps = WaveIn.GetCapabilities(n);
|
|
@@ -252,15 +276,13 @@ namespace XHWK.WKTool
|
252
|
276
|
data.Rows[n]["Value"] = caps.ProductName;
|
253
|
277
|
data.Rows[n]["Key"] = n + "";
|
254
|
278
|
}
|
255
|
|
- Dispatcher.Invoke(() =>
|
256
|
|
- {
|
257
|
|
- CmbMicrophoneList.ItemsSource = data.DefaultView;
|
258
|
|
- if (WaveIn.DeviceCount > 0)
|
259
|
|
- {
|
260
|
|
- CmbMicrophoneList.SelectedIndex = 0;
|
261
|
|
- }
|
262
|
|
- });
|
263
|
279
|
});
|
|
280
|
+
|
|
281
|
+ CmbMicrophoneList.ItemsSource = data.DefaultView;
|
|
282
|
+ if (WaveIn.DeviceCount > 0)
|
|
283
|
+ {
|
|
284
|
+ CmbMicrophoneList.SelectedIndex = 0;
|
|
285
|
+ }
|
264
|
286
|
}
|
265
|
287
|
|
266
|
288
|
private WaveInEvent waveIn = null;
|
|
@@ -275,39 +297,43 @@ namespace XHWK.WKTool
|
275
|
297
|
|
276
|
298
|
if (CmbMicrophoneList.SelectedIndex >= 0)
|
277
|
299
|
{
|
278
|
|
- waveIn = new WaveInEvent();
|
279
|
|
- waveIn.DeviceNumber = CmbMicrophoneList.SelectedIndex;
|
280
|
|
-
|
281
|
|
- //开始录音,写数据
|
282
|
|
- waveIn.DataAvailable += (o, e1) =>
|
|
300
|
+ var select_index = CmbMicrophoneList.SelectedIndex;
|
|
301
|
+ ThreadPool.QueueUserWorkItem((item) =>
|
283
|
302
|
{
|
284
|
|
- byte[] buf = e1.Buffer;
|
285
|
|
- float maxNumber = 0;
|
286
|
|
- for (int index = 0; index < buf.Length; index += 2)
|
287
|
|
- {
|
288
|
|
- short sample = (short)((buf[index + 1] << 8) | buf[index + 0]);
|
289
|
|
- float sample32 = sample / 32768f;
|
290
|
|
- sample32 = Math.Abs(sample32);
|
|
303
|
+ waveIn = new WaveInEvent();
|
|
304
|
+ waveIn.DeviceNumber = select_index;
|
291
|
305
|
|
292
|
|
- if (sample32 > maxNumber)
|
|
306
|
+ //开始录音,写数据
|
|
307
|
+ waveIn.DataAvailable += (o, e1) =>
|
|
308
|
+ {
|
|
309
|
+ byte[] buf = e1.Buffer;
|
|
310
|
+ float maxNumber = 0;
|
|
311
|
+ for (int index = 0; index < buf.Length; index += 2)
|
293
|
312
|
{
|
294
|
|
- maxNumber = sample32;
|
|
313
|
+ short sample = (short)((buf[index + 1] << 8) | buf[index + 0]);
|
|
314
|
+ float sample32 = sample / 32768f;
|
|
315
|
+ sample32 = Math.Abs(sample32);
|
|
316
|
+
|
|
317
|
+ if (sample32 > maxNumber)
|
|
318
|
+ {
|
|
319
|
+ maxNumber = sample32;
|
|
320
|
+ }
|
295
|
321
|
}
|
296
|
|
- }
|
297
|
322
|
|
298
|
|
- Dispatcher.Invoke(() =>
|
299
|
|
- {
|
300
|
|
- volumeProgressBar.Value = maxNumber * 100;
|
301
|
|
- });
|
302
|
|
- };
|
|
323
|
+ Dispatcher.Invoke(() =>
|
|
324
|
+ {
|
|
325
|
+ volumeProgressBar.Value = maxNumber * 100;
|
|
326
|
+ });
|
|
327
|
+ };
|
303
|
328
|
|
304
|
|
- //结束录音
|
305
|
|
- waveIn.RecordingStopped += (s, a) =>
|
306
|
|
- {
|
307
|
|
- waveIn.Dispose();
|
308
|
|
- };
|
|
329
|
+ //结束录音
|
|
330
|
+ waveIn.RecordingStopped += (s, a) =>
|
|
331
|
+ {
|
|
332
|
+ waveIn.Dispose();
|
|
333
|
+ };
|
309
|
334
|
|
310
|
|
- waveIn.StartRecording();
|
|
335
|
+ waveIn.StartRecording();
|
|
336
|
+ });
|
311
|
337
|
}
|
312
|
338
|
}
|
313
|
339
|
|
|
@@ -422,8 +448,10 @@ namespace XHWK.WKTool
|
422
|
448
|
/// <summary>
|
423
|
449
|
/// 重新
|
424
|
450
|
/// </summary>
|
425
|
|
- /// <param name="sender"></param>
|
426
|
|
- /// <param name="e"></param>
|
|
451
|
+ /// <param name="sender">
|
|
452
|
+ /// </param>
|
|
453
|
+ /// <param name="e">
|
|
454
|
+ /// </param>
|
427
|
455
|
private void BtnDetection_Click(object sender, RoutedEventArgs e)
|
428
|
456
|
{
|
429
|
457
|
cameraCheck();
|