|
|
@@ -31,43 +31,31 @@ namespace CallCenterApi.Interface.Controllers
|
|
31
|
31
|
string strSK = "aGmyOET05Os0atXBxFWXsC9qf1GgXv6R";
|
|
32
|
32
|
string backdata = "";
|
|
33
|
33
|
|
|
34
|
|
- //public SpeechDemo()
|
|
35
|
|
- //{
|
|
36
|
|
- // _asrClient = new Asr(strAK, strSK);
|
|
37
|
|
- // _ttsClient = new Tts("PuGGxl9vGrdijDTBYFBhEdVx", "aGmyOET05Os0atXBxFWXsC9qf1GgXv6R");
|
|
38
|
|
- //}
|
|
39
|
|
- string scallid = "453";
|
|
40
|
|
- string sfilepath = "E:\\callrec\\luyin\\20170508\\1004\\453_1004_173534.mp3";
|
|
|
34
|
+
|
|
41
|
35
|
public ActionResult GetCallOutprefix(string callid, string filepath)
|
|
42
|
36
|
{
|
|
43
|
37
|
ActionResult res = NoToken("未知错误,请重新登录");
|
|
44
|
38
|
//if (Request.IsAuthenticated)
|
|
45
|
|
- //{
|
|
46
|
|
- callid = scallid;
|
|
47
|
|
- filepath = sfilepath;
|
|
|
39
|
+ //{
|
|
48
|
40
|
_asrClient = new Asr(strAK, strSK);
|
|
49
|
41
|
_ttsClient = new Tts("PuGGxl9vGrdijDTBYFBhEdVx", "aGmyOET05Os0atXBxFWXsC9qf1GgXv6R");
|
|
50
|
|
- Init();//(callid, filepath);
|
|
51
|
|
-
|
|
52
|
|
-
|
|
|
42
|
+ Init();
|
|
53
|
43
|
res = Success("音频文件转换测试", backdata);
|
|
54
|
44
|
// }
|
|
55
|
45
|
return res;
|
|
56
|
46
|
}
|
|
57
|
47
|
|
|
58
|
48
|
|
|
59
|
|
- public void Init()//(string callid, string filepath)
|
|
|
49
|
+ public void Init()
|
|
60
|
50
|
{
|
|
61
|
51
|
//通过读取配置文件,获取数据库
|
|
62
|
|
-
|
|
63
|
|
- string dbpath = Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
|
|
64
|
|
- dbpath = "E:\\项目\\百度语音\\语音\\代码\\ASR_Speech\\ASR_Speech\\bin\\Debug\\Config.ini";
|
|
|
52
|
+ string dbpath = System.Threading.Thread.GetDomain().BaseDirectory + @"bin\Config.ini";//Environment.CurrentDirectory + @"\Config.ini"; //指定ini文件的路径
|
|
|
53
|
+
|
|
65
|
54
|
Common.IniFile ini = new Common.IniFile(dbpath);
|
|
66
|
55
|
string _dbset = ini.IniReadValue("基础设置SQL", "Catalog");
|
|
67
|
56
|
string _url = ini.IniReadValue("基础设置", "服务器地址");
|
|
68
|
57
|
//通过读取数据库,获得URL
|
|
69
|
|
- DataTable dt_Recor = DbHelperSQL.Query("select FilePath,CallId from T_Call_CallRecords where IsTranslate is NULL or IsTranslate!=1 ").Tables[0];
|
|
70
|
|
- //DataTable dt_Recor = Common.SQLHelper.QueryDataTable(_dbset, "select FilePath,CallId from T_Call_CallRecords where 1=1 ", CommandType.Text, null);
|
|
|
58
|
+ DataTable dt_Recor = DbHelperSQL.Query("select FilePath,CallId from T_Call_CallRecords where IsTranslate!=1 ").Tables[0];
|
|
71
|
59
|
if (dt_Recor.Rows.Count > 0)
|
|
72
|
60
|
{
|
|
73
|
61
|
int i = 0;
|
|
|
@@ -81,41 +69,20 @@ namespace CallCenterApi.Interface.Controllers
|
|
81
|
69
|
{
|
|
82
|
70
|
//通过cmd执行ffmpeg改变音频采样率
|
|
83
|
71
|
Process p = new Process();
|
|
84
|
|
- p.StartInfo.FileName = "cmd.exe";
|
|
|
72
|
+ p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "bin\\cmd.exe";
|
|
85
|
73
|
p.StartInfo.UseShellExecute = false;
|
|
86
|
74
|
p.StartInfo.RedirectStandardOutput = true;
|
|
87
|
75
|
p.StartInfo.RedirectStandardInput = true;
|
|
88
|
76
|
p.StartInfo.RedirectStandardError = true;
|
|
89
|
77
|
p.StartInfo.CreateNoWindow = true;
|
|
90
|
|
- //p.StartInfo.Arguments = "ffmpeg -i "+fileName+ " -ar 16000 "+ namePart + "New.wav";//参数以空格分隔,如果某个参数为空,可以传入””
|
|
91
|
|
-
|
|
92
|
|
- //p.Start();
|
|
93
|
|
- ////先进入cmd命令
|
|
94
|
|
- ////再打开FFmpeg.exe
|
|
95
|
|
- string ffmpegLocation = System.Threading.Thread.GetDomain().BaseDirectory;// +"bin\\";
|
|
96
|
|
- ////p.StandardInput.WriteLine("exit");
|
|
97
|
|
- //p.StandardInput.WriteLine("cd d/ " + ffmpegLocation + "ffmpeg.exe");
|
|
98
|
|
- //p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
|
|
99
|
|
-
|
|
100
|
|
- //判断是否存在文件夹,不存在则创建
|
|
101
|
|
- string voices_path = ffmpegLocation + "temp_voices";
|
|
102
|
|
- if (!Directory.Exists(voices_path))
|
|
103
|
|
- {
|
|
104
|
|
- Directory.CreateDirectory(voices_path);
|
|
105
|
|
- }
|
|
106
|
|
- //filepath:E:\callrec\luyin\20170506\1200\4_1200_164414.mp3
|
|
|
78
|
+
|
|
|
79
|
+ string ffmpegLocation = System.Threading.Thread.GetDomain().BaseDirectory;
|
|
|
80
|
+
|
|
107
|
81
|
string[] filepaths = filepath.Split(new char[] { '\\' });
|
|
108
|
|
- //res_audiopath:http://192.168.5.7:88/callrec/luyin/20170506/1200/4_1200_164414.mp3
|
|
|
82
|
+
|
|
109
|
83
|
string res_audiopath = filepath.Replace(filepath.Substring(0, 2), _url).Replace("mp3", "wav").Replace(@"\", @"/");
|
|
110
|
|
- //voices_path:D:\项目\XFTest_WITHDB\XFTest\bin\Debug
|
|
111
|
|
- //namePart:D:\项目\XFTest_WITHDB\XFTest\bin\Debug\temp_voices\4_1200_164414.wav
|
|
112
|
|
- string namePart = voices_path + @"\" + filepaths.Last().Replace("mp3", "wav");
|
|
113
|
|
- //pcm和WAV格式文件可以解析出来
|
|
114
|
|
- //this.AsrData(p, ffmpegLocation, res_audiopath, callid, namePart);
|
|
115
|
|
- //20171013 用本地文件测试
|
|
116
|
|
- //this.AsrData(p, ffmpegLocation, ffmpegLocation + "0.mp3", callid, namePart);
|
|
117
|
|
- //20171016
|
|
118
|
|
- this.AsrData(p, ffmpegLocation, "http://192.168.5.7:88/CallREC/luyin/20170908/1/427_1_141423.wav", callid, namePart);
|
|
|
84
|
+
|
|
|
85
|
+ this.AsrData(p, ffmpegLocation, res_audiopath, callid);
|
|
119
|
86
|
}
|
|
120
|
87
|
}
|
|
121
|
88
|
}
|
|
|
@@ -123,7 +90,7 @@ namespace CallCenterApi.Interface.Controllers
|
|
123
|
90
|
/// <summary>
|
|
124
|
91
|
/// 识别本地文件
|
|
125
|
92
|
/// </summary>
|
|
126
|
|
- public void AsrData(Process p, string filelocation, string filepath, string callid, string namepart)
|
|
|
93
|
+ public void AsrData(Process p, string filelocation, string filepath, string callid)
|
|
127
|
94
|
{
|
|
128
|
95
|
#region 读取本地文件
|
|
129
|
96
|
//int audiocounts = SplitAudio(filepath);
|
|
|
@@ -206,15 +173,10 @@ namespace CallCenterApi.Interface.Controllers
|
|
206
|
173
|
for (int i = 0; i < audiocounts; i++)
|
|
207
|
174
|
{
|
|
208
|
175
|
p.Start();
|
|
209
|
|
- //先进入cmd命令
|
|
210
|
|
- //再打开FFmpeg.exe
|
|
211
|
|
-
|
|
212
|
|
- //p.StandardInput.WriteLine("exit");
|
|
213
|
|
- p.StandardInput.WriteLine("cd d/ " + filelocation + "ffmpeg.exe");
|
|
214
|
|
- p.StandardInput.WriteLine(filelocation.TrimEnd('\\'));
|
|
215
|
|
-
|
|
216
|
|
- //p.StandardInput.WriteLine("ffmpeg -i " + temp_filename + i + ".mp3 -f pcm -ar 16000 -ac 1 -ab 16 " + namepart.Replace(@"/", @"\"));
|
|
217
|
|
- string changefile = "ffmpeg -i " + filelocation + temp_filename + i + ".wav -acodec pcm_s16le -f s16le -ar 16000 -ac 1 " + filelocation + temp_filename + i + ".pcm";
|
|
|
176
|
+ p.StandardInput.WriteLine("cd "+filelocation+"bin");
|
|
|
177
|
+ p.StandardInput.WriteLine("ffmpeg.exe");
|
|
|
178
|
+
|
|
|
179
|
+ string changefile = "ffmpeg -i " + filelocation + "bin\\" + temp_filename + i + ".wav -acodec pcm_s16le -f s16le -ar 16000 -ac 1 " + filelocation + "bin\\" + temp_filename + i + ".pcm";
|
|
218
|
180
|
|
|
219
|
181
|
p.StandardInput.WriteLine(changefile);
|
|
220
|
182
|
Thread.Sleep(3000);
|
|
|
@@ -222,7 +184,7 @@ namespace CallCenterApi.Interface.Controllers
|
|
222
|
184
|
//Kill 是终止没有图形化界面的进程的唯一方法。
|
|
223
|
185
|
//p.Kill();
|
|
224
|
186
|
//此处可以返回一个字符串,此例是返回压缩成功之后的一个文件路径
|
|
225
|
|
- var data = System.IO.File.ReadAllBytes(filelocation + temp_filename + i + ".pcm");
|
|
|
187
|
+ var data = System.IO.File.ReadAllBytes(filelocation+"bin\\" + temp_filename + i + ".pcm");
|
|
226
|
188
|
var result_Json = _asrClient.Recognize(data, "pcm", 16000);
|
|
227
|
189
|
if (rec_result != null)
|
|
228
|
190
|
{
|
|
|
@@ -240,19 +202,21 @@ namespace CallCenterApi.Interface.Controllers
|
|
240
|
202
|
}
|
|
241
|
203
|
}
|
|
242
|
204
|
backdata = rec_result;
|
|
243
|
|
- //Console.Write("\n语音听写结束\n");
|
|
244
|
|
- //Console.Write("=============================================================\n");
|
|
245
|
|
- //Console.Write(rec_result);
|
|
246
|
|
- //Console.Write("\n=============================================================\n");
|
|
|
205
|
+
|
|
247
|
206
|
int exe_res = DbHelperSQL.ExecuteSql("update T_Call_CallRecords set IsTranslate=1,RecordsContent='" + rec_result + "' where CallId='" + callid + "'");
|
|
248
|
207
|
if (exe_res > 0)
|
|
249
|
208
|
{
|
|
250
|
|
- //Console.WriteLine("\n数据库更新成功\n");
|
|
251
|
|
- //操作完删除转换后的文件
|
|
252
|
|
- string x = namepart.Replace(@"/", @"\");
|
|
253
|
|
- if (System.IO.File.Exists(filelocation + namepart.Replace(@"/", @"\")))
|
|
|
209
|
+ //删除转换时缓存文件
|
|
|
210
|
+ for (int i = 0; i < audiocounts; i++)
|
|
254
|
211
|
{
|
|
255
|
|
- System.IO.File.Delete(filelocation + namepart.Replace(@"/", @"\"));
|
|
|
212
|
+ if (System.IO.File.Exists(filelocation + "bin\\" + temp_filename + i + ".wav"))
|
|
|
213
|
+ {
|
|
|
214
|
+ System.IO.File.Delete(filelocation + "bin\\" + temp_filename + i + ".wav");
|
|
|
215
|
+ }
|
|
|
216
|
+ if (System.IO.File.Exists(filelocation + "bin\\" + temp_filename + i + ".pcm"))
|
|
|
217
|
+ {
|
|
|
218
|
+ System.IO.File.Delete(filelocation + "bin\\" + temp_filename + i + ".pcm");
|
|
|
219
|
+ }
|
|
256
|
220
|
}
|
|
257
|
221
|
}
|
|
258
|
222
|
#endregion
|
|
|
@@ -298,17 +262,19 @@ namespace CallCenterApi.Interface.Controllers
|
|
298
|
262
|
if (sec > 30)
|
|
299
|
263
|
{
|
|
300
|
264
|
Process p = new Process();
|
|
301
|
|
- p.StartInfo.FileName = "cmd.exe";
|
|
|
265
|
+ p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "bin\\cmd.exe";//"cmd.exe";
|
|
302
|
266
|
p.StartInfo.UseShellExecute = false;
|
|
303
|
267
|
p.StartInfo.RedirectStandardOutput = true;
|
|
304
|
268
|
p.StartInfo.RedirectStandardInput = true;
|
|
305
|
269
|
p.StartInfo.RedirectStandardError = true;
|
|
306
|
|
- // p.StartInfo.CreateNoWindow = true;
|
|
|
270
|
+ p.StartInfo.CreateNoWindow = false;
|
|
307
|
271
|
p.Start();
|
|
308
|
272
|
string ffmpegLocation = System.Threading.Thread.GetDomain().BaseDirectory + "bin\\";
|
|
309
|
|
- p.StandardInput.WriteLine("exit");
|
|
310
|
|
- p.StandardInput.WriteLine("cd d/ " + ffmpegLocation + "ffmpeg.exe");
|
|
311
|
|
- p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
|
|
|
273
|
+
|
|
|
274
|
+ p.StandardInput.WriteLine("cd " + ffmpegLocation.TrimEnd('\\'));
|
|
|
275
|
+ p.StandardInput.WriteLine("ffmpeg.exe");
|
|
|
276
|
+ p.StandardInput.AutoFlush = true;
|
|
|
277
|
+
|
|
312
|
278
|
string fileName = System.IO.Path.GetFileName(filepath).Split('.')[0];
|
|
313
|
279
|
index = sec / 28 + 1;
|
|
314
|
280
|
|