|
@@ -23,6 +23,14 @@ namespace Common.system
|
23
|
23
|
/// </summary>
|
24
|
24
|
string LogPath = "";
|
25
|
25
|
/// <summary>
|
|
26
|
+ /// 是否可以录制扬声器
|
|
27
|
+ /// </summary>
|
|
28
|
+ bool IsRecordSpeaker = true;
|
|
29
|
+ /// <summary>
|
|
30
|
+ /// 是否可以录制麦克风
|
|
31
|
+ /// </summary>
|
|
32
|
+ bool IsRecordMicrophone = true;
|
|
33
|
+ /// <summary>
|
26
|
34
|
/// 录制屏幕
|
27
|
35
|
/// </summary>
|
28
|
36
|
/// <param name="FilePath">文件存储路径</param>
|
|
@@ -45,56 +53,84 @@ namespace Common.system
|
45
|
53
|
myProcess = new Process();
|
46
|
54
|
LogPath = CreateffmpegLog();
|
47
|
55
|
string MicrophoneName = null;
|
48
|
|
- string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
|
|
56
|
+ #region 检测麦克风扬声器
|
|
57
|
+ string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
|
|
58
|
+ string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
|
49
|
59
|
try
|
50
|
60
|
{
|
51
|
|
- FileToolsCommon.DeleteFile(audioTestPath);
|
|
61
|
+ FileToolsCommon.DeleteFile(audioSpeakerPath);
|
|
62
|
+ FileToolsCommon.DeleteFile(audioMicrophonePath);
|
52
|
63
|
}
|
53
|
64
|
catch (Exception)
|
54
|
65
|
{
|
55
|
66
|
|
56
|
67
|
}
|
57
|
|
- if (StartRecordAudio(audioTestPath))
|
|
68
|
+ if(StartRecordSpeakerAudio(audioSpeakerPath))
|
58
|
69
|
{
|
59
|
|
- MicrophoneName = GetMicrophone();
|
|
70
|
+ IsRecordSpeaker = true;
|
|
71
|
+ }
|
|
72
|
+ else
|
|
73
|
+ {
|
|
74
|
+ //无法录制扬声器音频
|
|
75
|
+ IsRecordSpeaker = false;
|
60
|
76
|
}
|
61
|
77
|
StopRecordAudio();
|
|
78
|
+ Thread.Sleep(500);
|
|
79
|
+ if (StartRecordAudio(audioMicrophonePath))
|
|
80
|
+ {
|
|
81
|
+ IsRecordMicrophone = true;
|
|
82
|
+ }
|
|
83
|
+ else
|
|
84
|
+ {
|
|
85
|
+ //无法录制扬声器
|
|
86
|
+ IsRecordMicrophone = false;
|
|
87
|
+ }
|
|
88
|
+ StopRecordAudio();
|
|
89
|
+ #endregion
|
62
|
90
|
myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
91
|
+ string SpeakerStr = "";
|
|
92
|
+ string MicrophoneStr = "";
|
|
93
|
+ if (IsRecordSpeaker)
|
|
94
|
+ {
|
|
95
|
+ SpeakerStr = "-f dshow -i audio=\"virtual-audio-capturer\" ";
|
|
96
|
+ }
|
|
97
|
+ if(IsRecordMicrophone)
|
|
98
|
+ {
|
|
99
|
+ MicrophoneName = GetMicrophone();
|
|
100
|
+ if (!string.IsNullOrWhiteSpace(MicrophoneName))
|
|
101
|
+ {
|
|
102
|
+ MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
|
|
103
|
+ }
|
|
104
|
+ }
|
63
|
105
|
switch (Extension.ToUpper())
|
64
|
106
|
{
|
65
|
107
|
case ".MP4":
|
66
|
|
- if (string.IsNullOrWhiteSpace(MicrophoneName))
|
67
|
|
- {
|
68
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f avi " + PathName; //ffmpeg的参数
|
69
|
|
- }
|
70
|
|
- else
|
71
|
|
- {
|
72
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
73
|
|
- MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName; //ffmpeg的参数
|
74
|
|
- }
|
|
108
|
+ myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
|
|
109
|
+ //if (string.IsNullOrWhiteSpace(MicrophoneName))
|
|
110
|
+ //{
|
|
111
|
+ // myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 " + PathName; //ffmpeg的参数
|
|
112
|
+ //}
|
|
113
|
+ //else
|
|
114
|
+ //{
|
|
115
|
+ // myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
|
116
|
+ // MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName; //ffmpeg的参数
|
|
117
|
+ //}
|
75
|
118
|
break;
|
76
|
119
|
case ".AVI":
|
77
|
120
|
case ".FLV":
|
78
|
|
- if (string.IsNullOrWhiteSpace(MicrophoneName))
|
79
|
|
- {
|
80
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f " + Extension.ToLower() + " " + PathName; //ffmpeg的参数
|
81
|
|
- }
|
82
|
|
- else
|
83
|
|
- {
|
84
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
85
|
|
- MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 -f " + Extension.ToLower() + " " + PathName; //ffmpeg的参数
|
86
|
|
- }
|
|
121
|
+ myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".","") + " " + PathName;
|
|
122
|
+ //if (string.IsNullOrWhiteSpace(MicrophoneName))
|
|
123
|
+ //{
|
|
124
|
+ // myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f " + Extension.ToLower() + " " + PathName; //ffmpeg的参数
|
|
125
|
+ //}
|
|
126
|
+ //else
|
|
127
|
+ //{
|
|
128
|
+ // myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
|
129
|
+ // MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 -f " + Extension.ToLower() + " " + PathName; //ffmpeg的参数
|
|
130
|
+ //}
|
87
|
131
|
break;
|
88
|
132
|
default:
|
89
|
|
- if (string.IsNullOrWhiteSpace(MicrophoneName))
|
90
|
|
- {
|
91
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f avi " + PathName; //ffmpeg的参数
|
92
|
|
- }
|
93
|
|
- else
|
94
|
|
- {
|
95
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
96
|
|
- MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName; //ffmpeg的参数
|
97
|
|
- }
|
|
133
|
+ myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
|
98
|
134
|
break;
|
99
|
135
|
}
|
100
|
136
|
myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
|
@@ -110,7 +146,7 @@ namespace Common.system
|
110
|
146
|
/// 录制音频
|
111
|
147
|
/// </summary>
|
112
|
148
|
/// <param name="Mp3Path">MP3音频位置</param>
|
113
|
|
- public void StartRecordingAudio(string Mp3Path)
|
|
149
|
+ public bool StartRecordingAudio(string Mp3Path)
|
114
|
150
|
{
|
115
|
151
|
while (myProcess != null)
|
116
|
152
|
{
|
|
@@ -125,33 +161,67 @@ namespace Common.system
|
125
|
161
|
{
|
126
|
162
|
KillProcess.Kill();
|
127
|
163
|
}
|
128
|
|
- myProcess = new Process();
|
129
|
|
- LogPath = CreateffmpegLog();
|
130
|
|
- this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
131
|
164
|
string MicrophoneName = null;
|
132
|
|
- string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
|
|
165
|
+ #region 检测麦克风扬声器
|
|
166
|
+ string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
|
|
167
|
+ string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
|
133
|
168
|
try
|
134
|
169
|
{
|
135
|
|
- FileToolsCommon.DeleteFile(audioTestPath);
|
|
170
|
+ FileToolsCommon.DeleteFile(audioSpeakerPath);
|
|
171
|
+ FileToolsCommon.DeleteFile(audioMicrophonePath);
|
136
|
172
|
}
|
137
|
173
|
catch (Exception)
|
138
|
174
|
{
|
139
|
175
|
|
140
|
176
|
}
|
141
|
|
- if (StartRecordAudio(audioTestPath))
|
|
177
|
+ if (StartRecordSpeakerAudio(audioSpeakerPath))
|
142
|
178
|
{
|
143
|
|
- MicrophoneName = GetMicrophone();
|
|
179
|
+ IsRecordSpeaker = true;
|
|
180
|
+ }
|
|
181
|
+ else
|
|
182
|
+ {
|
|
183
|
+ //无法录制扬声器音频
|
|
184
|
+ IsRecordSpeaker = false;
|
144
|
185
|
}
|
145
|
186
|
StopRecordAudio();
|
146
|
|
- if (string.IsNullOrWhiteSpace(MicrophoneName))
|
|
187
|
+ Thread.Sleep(500);
|
|
188
|
+ if (StartRecordAudio(audioMicrophonePath))
|
147
|
189
|
{
|
148
|
|
- myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
|
|
190
|
+ IsRecordMicrophone = true;
|
|
191
|
+ MicrophoneName = GetMicrophone();
|
149
|
192
|
}
|
150
|
193
|
else
|
|
194
|
+ {
|
|
195
|
+ //无法录制扬声器
|
|
196
|
+ IsRecordMicrophone = false;
|
|
197
|
+ }
|
|
198
|
+ StopRecordAudio();
|
|
199
|
+ if (!IsRecordSpeaker && !IsRecordMicrophone)
|
|
200
|
+ {
|
|
201
|
+ return false;
|
|
202
|
+ }
|
|
203
|
+ #endregion
|
|
204
|
+ myProcess = new Process();
|
|
205
|
+ LogPath = CreateffmpegLog();
|
|
206
|
+ this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
207
|
+ if(IsRecordSpeaker && IsRecordMicrophone)
|
151
|
208
|
{
|
152
|
209
|
myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
|
153
|
210
|
MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
|
154
|
211
|
}
|
|
212
|
+ else if(IsRecordSpeaker)
|
|
213
|
+ {
|
|
214
|
+ myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
|
|
215
|
+ }
|
|
216
|
+ else if(IsRecordMicrophone)
|
|
217
|
+ {
|
|
218
|
+ //录制麦克风
|
|
219
|
+ if (!string.IsNullOrWhiteSpace(MicrophoneName))
|
|
220
|
+ {
|
|
221
|
+ myProcess.StartInfo.Arguments = "-f dshow -i audio=\"" +
|
|
222
|
+ MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
|
|
223
|
+ }
|
|
224
|
+ }
|
155
|
225
|
myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
156
|
226
|
myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
157
|
227
|
myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
@@ -160,6 +230,7 @@ namespace Common.system
|
160
|
230
|
myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
161
|
231
|
myProcess.Start(); //启动线程
|
162
|
232
|
myProcess.BeginErrorReadLine(); //开始异步读取
|
|
233
|
+ return true;
|
163
|
234
|
}
|
164
|
235
|
|
165
|
236
|
/// <summary>
|
|
@@ -252,31 +323,41 @@ namespace Common.system
|
252
|
323
|
}
|
253
|
324
|
myProcess = new Process();
|
254
|
325
|
LogPath = CreateffmpegLog();
|
|
326
|
+ string mp3Str = "";
|
|
327
|
+ #region 判断音频是否存在
|
|
328
|
+ if (!string.IsNullOrWhiteSpace(Mp3Path))
|
|
329
|
+ {
|
|
330
|
+ if (FileToolsCommon.IsExistFile(Mp3Path))
|
|
331
|
+ {
|
|
332
|
+ mp3Str = "-i " + Mp3Path;
|
|
333
|
+ }
|
|
334
|
+ }
|
|
335
|
+ #endregion
|
255
|
336
|
this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
256
|
337
|
switch (Extension.ToUpper())
|
257
|
338
|
{
|
258
|
339
|
case ".MP4":
|
259
|
340
|
myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
260
|
|
- ImageListPath + @"%d.png -i " +
|
261
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
|
341
|
+ ImageListPath + @"%d.png " +
|
|
342
|
+ mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
262
|
343
|
VideoSavePath;
|
263
|
344
|
break;
|
264
|
345
|
case ".AVI":
|
265
|
346
|
myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
266
|
|
- ImageListPath + @"%d.png -i " +
|
267
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
|
|
347
|
+ ImageListPath + @"%d.png " +
|
|
348
|
+ mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
|
268
|
349
|
VideoSavePath;
|
269
|
350
|
break;
|
270
|
351
|
case ".FLV":
|
271
|
352
|
myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
272
|
|
- ImageListPath + @"%d.png -i " +
|
273
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
|
|
353
|
+ ImageListPath + @"%d.png " +
|
|
354
|
+ mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
|
274
|
355
|
VideoSavePath;
|
275
|
356
|
break;
|
276
|
357
|
default:
|
277
|
358
|
myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
278
|
|
- ImageListPath + @"%d.png -i " +
|
279
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
|
359
|
+ ImageListPath + @"%d.png " +
|
|
360
|
+ mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
280
|
361
|
VideoSavePath;
|
281
|
362
|
break;
|
282
|
363
|
}
|
|
@@ -339,12 +420,29 @@ namespace Common.system
|
339
|
420
|
//路径
|
340
|
421
|
string FilePath = (string)FilePathobj;
|
341
|
422
|
string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
342
|
|
- string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
|
423
|
+ //扩展名
|
|
424
|
+ string Extension = FileToolsCommon.GetIOExtension(FilePath);
|
343
|
425
|
//Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
344
|
426
|
//foreach (var KillProcess in KillProcessArray)
|
345
|
427
|
//{
|
346
|
428
|
// KillProcess.Kill();
|
347
|
429
|
//}
|
|
430
|
+ #region 判断文件是否存在
|
|
431
|
+ if (Extension.ToUpper() == ".MP3")
|
|
432
|
+ {
|
|
433
|
+ if (!FileToolsCommon.IsExistFile(Path + "temp/filelist.d"))
|
|
434
|
+ {
|
|
435
|
+ return;
|
|
436
|
+ }
|
|
437
|
+ }
|
|
438
|
+ else
|
|
439
|
+ {
|
|
440
|
+ if (!FileToolsCommon.IsExistFile(Path + "temprs/filelist.d"))
|
|
441
|
+ {
|
|
442
|
+ return;
|
|
443
|
+ }
|
|
444
|
+ }
|
|
445
|
+ #endregion
|
348
|
446
|
myProcess = new Process();
|
349
|
447
|
LogPath = CreateffmpegLog();
|
350
|
448
|
this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
@@ -633,7 +731,7 @@ namespace Common.system
|
633
|
731
|
//录制麦克风的声音
|
634
|
732
|
WaveInEvent waveIn = null; //new WaveInEvent();
|
635
|
733
|
/// <summary>
|
636
|
|
- /// 开始录制
|
|
734
|
+ /// 开始录制麦克风
|
637
|
735
|
/// </summary>
|
638
|
736
|
public bool StartRecordAudio(string audioFile)
|
639
|
737
|
{
|
|
@@ -654,6 +752,15 @@ namespace Common.system
|
654
|
752
|
writer.Dispose();
|
655
|
753
|
writer = null;
|
656
|
754
|
waveIn.Dispose();
|
|
755
|
+ waveIn = null;
|
|
756
|
+ try
|
|
757
|
+ {
|
|
758
|
+ FileToolsCommon.DeleteFile(audioFile);
|
|
759
|
+ }
|
|
760
|
+ catch (Exception)
|
|
761
|
+ {
|
|
762
|
+
|
|
763
|
+ }
|
657
|
764
|
};
|
658
|
765
|
waveIn.StartRecording();
|
659
|
766
|
return true;
|
|
@@ -665,16 +772,69 @@ namespace Common.system
|
665
|
772
|
}
|
666
|
773
|
}
|
667
|
774
|
|
668
|
|
- //结束录制
|
|
775
|
+ /// <summary>
|
|
776
|
+ /// 结束录制音频
|
|
777
|
+ /// </summary>
|
669
|
778
|
public void StopRecordAudio()
|
670
|
779
|
{
|
671
|
780
|
try
|
672
|
781
|
{
|
673
|
|
- waveIn.StopRecording();
|
|
782
|
+ if (waveIn != null)
|
|
783
|
+ {
|
|
784
|
+ waveIn.StopRecording();
|
|
785
|
+ }
|
|
786
|
+ if (capture != null)
|
|
787
|
+ {
|
|
788
|
+ capture.StopRecording();
|
|
789
|
+ }
|
|
790
|
+ }
|
|
791
|
+ catch (Exception ex)
|
|
792
|
+ {
|
|
793
|
+ LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
794
|
+ }
|
|
795
|
+ }
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+ //录制扬声器的声音
|
|
799
|
+ WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
|
|
800
|
+
|
|
801
|
+ /// <summary>
|
|
802
|
+ /// 开始录制扬声器
|
|
803
|
+ /// </summary>
|
|
804
|
+ public bool StartRecordSpeakerAudio(string audioFile)
|
|
805
|
+ {
|
|
806
|
+ try
|
|
807
|
+ {
|
|
808
|
+ capture = new WasapiLoopbackCapture();
|
|
809
|
+ //生成音频文件的对象
|
|
810
|
+ WaveFileWriter writer = new WaveFileWriter(audioFile, capture.WaveFormat);
|
|
811
|
+ capture.DataAvailable += (s, a) =>
|
|
812
|
+ {
|
|
813
|
+ writer.Write(a.Buffer, 0, a.BytesRecorded);
|
|
814
|
+ };
|
|
815
|
+ //结束录音
|
|
816
|
+ capture.RecordingStopped += (s, a) =>
|
|
817
|
+ {
|
|
818
|
+ writer.Dispose();
|
|
819
|
+ writer = null;
|
|
820
|
+ capture.Dispose();
|
|
821
|
+ capture = null;
|
|
822
|
+ try
|
|
823
|
+ {
|
|
824
|
+ FileToolsCommon.DeleteFile(audioFile);
|
|
825
|
+ }
|
|
826
|
+ catch (Exception)
|
|
827
|
+ {
|
|
828
|
+
|
|
829
|
+ }
|
|
830
|
+ };
|
|
831
|
+ capture.StartRecording();
|
|
832
|
+ return true;
|
674
|
833
|
}
|
675
|
834
|
catch (Exception ex)
|
676
|
835
|
{
|
677
|
836
|
LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
837
|
+ return false;
|
678
|
838
|
}
|
679
|
839
|
}
|
680
|
840
|
}
|