|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+using CallCenter.Utility;
|
|
|
2
|
+using CallCenterApi.Interface.Controllers.Base;
|
|
|
3
|
+using System;
|
|
|
4
|
+using System.Collections.Generic;
|
|
|
5
|
+using System.Diagnostics;
|
|
|
6
|
+using System.IO;
|
|
|
7
|
+using System.Linq;
|
|
|
8
|
+using System.Text;
|
|
|
9
|
+using System.Threading;
|
|
|
10
|
+using System.Web;
|
|
|
11
|
+using System.Web.Mvc;
|
|
|
12
|
+
|
|
|
13
|
+namespace CallCenterApi.Interface.Controllers
|
|
|
14
|
+{
|
|
|
15
|
+ public class UploadFileController : BaseController
|
|
|
16
|
+ {
|
|
|
17
|
+ // GET: UploadFile
|
|
|
18
|
+ //public ActionResult Index()
|
|
|
19
|
+ //{
|
|
|
20
|
+ // return View();
|
|
|
21
|
+ //}
|
|
|
22
|
+
|
|
|
23
|
+ public ActionResult UploadToFTP()
|
|
|
24
|
+ {
|
|
|
25
|
+ ActionResult res = NoToken("未知错误,请重新登录");
|
|
|
26
|
+ #region 前后端分离上传并修改文件格式
|
|
|
27
|
+ //string fullFileName = this.txtfileUpload.FileName; //文件路径名
|
|
|
28
|
+ HttpPostedFile _upFile = RequestString.GetFile("upFile");
|
|
|
29
|
+ if (_upFile != null)
|
|
|
30
|
+ {
|
|
|
31
|
+ string datename = DateTime.Now.ToString("yyyyMMddHHMMss");
|
|
|
32
|
+ string fullFileName = datename + "_" + _upFile.FileName;
|
|
|
33
|
+ string path = Server.MapPath(this.Request.ApplicationPath + "~/upload/");
|
|
|
34
|
+ if (!System.IO.Directory.Exists(path))
|
|
|
35
|
+ {
|
|
|
36
|
+ System.IO.Directory.CreateDirectory(path);
|
|
|
37
|
+ }
|
|
|
38
|
+ path = path + fullFileName;
|
|
|
39
|
+ string physicalpath = Server.MapPath(path);
|
|
|
40
|
+ _upFile.SaveAs(physicalpath);
|
|
|
41
|
+
|
|
|
42
|
+ #region 修改音频格式
|
|
|
43
|
+ if (!string.IsNullOrEmpty(physicalpath))
|
|
|
44
|
+ {
|
|
|
45
|
+ //通过cmd执行ffmpeg改变音频采样率
|
|
|
46
|
+ Process p = new Process();
|
|
|
47
|
+ p.StartInfo.FileName = "cmd.exe";
|
|
|
48
|
+ p.StartInfo.UseShellExecute = false;
|
|
|
49
|
+ p.StartInfo.RedirectStandardOutput = true;
|
|
|
50
|
+ p.StartInfo.RedirectStandardInput = true;
|
|
|
51
|
+ p.StartInfo.RedirectStandardError = true;
|
|
|
52
|
+ p.StartInfo.CreateNoWindow = true;
|
|
|
53
|
+ //p.StartInfo.Arguments = "ffmpeg -i "+fileName+ " -ar 16000 "+ namePart + "New.wav";//参数以空格分隔,如果某个参数为空,可以传入””
|
|
|
54
|
+
|
|
|
55
|
+ //p.Start();
|
|
|
56
|
+ ////先进入cmd命令
|
|
|
57
|
+ ////再打开FFmpeg.exe
|
|
|
58
|
+ string ffmpegLocation = System.Threading.Thread.GetDomain().BaseDirectory;
|
|
|
59
|
+ ////p.StandardInput.WriteLine("exit");
|
|
|
60
|
+ //p.StandardInput.WriteLine("cd d/ " + ffmpegLocation + "ffmpeg.exe");
|
|
|
61
|
+ //p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
|
|
|
62
|
+
|
|
|
63
|
+ //判断是否存在文件夹,不存在则创建
|
|
|
64
|
+ string voices_path = ffmpegLocation + "temp_voices";
|
|
|
65
|
+ if (!Directory.Exists(voices_path))
|
|
|
66
|
+ {
|
|
|
67
|
+ Directory.CreateDirectory(voices_path);
|
|
|
68
|
+ }
|
|
|
69
|
+ string temp_filename = physicalpath.Split('/').Last().Split('.')[0] + "_temp_";
|
|
|
70
|
+
|
|
|
71
|
+ p.Start();
|
|
|
72
|
+ //先进入cmd命令
|
|
|
73
|
+ //再打开FFmpeg.exe
|
|
|
74
|
+ //p.StandardInput.WriteLine("exit");
|
|
|
75
|
+ p.StandardInput.WriteLine("cd d/ " + ffmpegLocation + "ffmpeg.exe");
|
|
|
76
|
+ p.StandardInput.WriteLine(ffmpegLocation.TrimEnd('\\'));
|
|
|
77
|
+
|
|
|
78
|
+ //p.StandardInput.WriteLine("ffmpeg -i " + temp_filename + i + ".mp3 -f pcm -ar 16000 -ac 1 -ab 16 " + namepart.Replace(@"/", @"\"));
|
|
|
79
|
+ //string changefile = "ffmpeg -i " + physicalpath + " -acodec pcm_s16le -f s16le -ar 16000 -ac 1 " + ffmpegLocation + temp_filename + ".pcm";
|
|
|
80
|
+ string changefile = "ffmpeg -i " + physicalpath + " -acodec pcm_s16le -f s16le -ar 8000 -ac 1 " + ffmpegLocation + temp_filename + ".pcm";
|
|
|
81
|
+
|
|
|
82
|
+ p.StandardInput.WriteLine(changefile);
|
|
|
83
|
+ Thread.Sleep(3000);
|
|
|
84
|
+ p.StandardInput.WriteLine("exit");
|
|
|
85
|
+ //Kill 是终止没有图形化界面的进程的唯一方法。
|
|
|
86
|
+ p.Kill();
|
|
|
87
|
+
|
|
|
88
|
+ #region 上传
|
|
|
89
|
+ uploadFile upfile = new uploadFile();
|
|
|
90
|
+ //通过读取配置文件,获取数据库
|
|
|
91
|
+ string _ftp = Configs.GetValue("ftp");
|
|
|
92
|
+ string _acc = Configs.GetValue("account");
|
|
|
93
|
+ string _pwd = Configs.GetValue("password");
|
|
|
94
|
+
|
|
|
95
|
+ upfile.ftpPath = _ftp;
|
|
|
96
|
+ upfile.ftpUserID = _acc;
|
|
|
97
|
+ upfile.ftpPassword = _pwd;
|
|
|
98
|
+ //FileInfo fi = new FileInfo(path);
|
|
|
99
|
+ FileInfo fi = new FileInfo(physicalpath);
|
|
|
100
|
+ //string res = upfile.UploadLocalToFtp(path);
|
|
|
101
|
+ //string res = upfile.UploadLocalToFtp(physicalpath);
|
|
|
102
|
+ string uploadres = upfile.UploadLocalToFtp(ffmpegLocation + temp_filename + ".pcm");
|
|
|
103
|
+ if (uploadres == "上传成功!")
|
|
|
104
|
+ {
|
|
|
105
|
+ //写入日志
|
|
|
106
|
+ string logfile = Server.MapPath("~/log.txt");
|
|
|
107
|
+ if (!System.IO.File.Exists(logfile))
|
|
|
108
|
+ {
|
|
|
109
|
+ System.IO.File.Create(logfile);
|
|
|
110
|
+ }
|
|
|
111
|
+ //开始写入
|
|
|
112
|
+ string str = DateTime.Now.ToString() + " 文件" + fullFileName + "上传成功";
|
|
|
113
|
+ System.IO.File.AppendAllLines(logfile, new string[] { str }, Encoding.GetEncoding("gb2312"));
|
|
|
114
|
+ res = Success("上传成功");
|
|
|
115
|
+ }
|
|
|
116
|
+ #endregion
|
|
|
117
|
+ }
|
|
|
118
|
+ #endregion
|
|
|
119
|
+ }
|
|
|
120
|
+ else
|
|
|
121
|
+ res = Error("参数传入失败");
|
|
|
122
|
+ #endregion
|
|
|
123
|
+ return res;
|
|
|
124
|
+ }
|
|
|
125
|
+ }
|
|
|
126
|
+}
|