Browse Source

优化语音播放

master
胡超1 1 year ago
parent
commit
fb172d3848
  1. 28
      CPF_Cef/Common/ChunkedUpload.cs
  2. 4
      CPF_Cef/FrmMain.cs
  3. 68
      CPF_Cef/MainModel.cs

28
CPF_Cef/Common/ChunkedUpload.cs

@ -9,6 +9,7 @@ using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AksWebBrowser.Common
@ -761,5 +762,32 @@ namespace AksWebBrowser.Common
ServicePointManager.DefaultConnectionLimit = 1000;
ServicePointManager.Expect100Continue = false;
}
public static string NumberToChinese(int number)
{
string[] chineseNumbers = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string[] chineseUnits = new string[] { "", "十", "百", "千", "万" };
string result = "";
int unitPlace = 0;
if (number == 0)
{
return chineseNumbers[0];
}
while (number > 0)
{
int part = number % 10;
if (part != 0 || (part == 0 && result.Length > 0 && result[0] != '零'))
{
result = string.Format("{0}{1}{2}", chineseNumbers[part], chineseUnits[unitPlace], result);
}
number /= 10;
unitPlace++;
}
return result;
}
}
}

4
CPF_Cef/FrmMain.cs

@ -81,9 +81,9 @@ namespace AksWebBrowser
//浏览器大小
Parame.webBrowser.Width = w;
Parame.webBrowser.Height = h;
Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out";
//Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out";
//Parame.webBrowser.Url = "http://192.168.0.232:8848/html/index.html";
//Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows
//webBrowser.ShowDev();

68
CPF_Cef/MainModel.cs

@ -401,10 +401,7 @@ namespace AksWebBrowser
{
if (ispaye)
{
Task.Run(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}";
SubmitLogs(result, "payleText");
return result;
@ -451,7 +448,7 @@ namespace AksWebBrowser
}
else
{
Task.Run(() => { string command = $"sox {tempFile} -d"; ShllCommad(command); });
Task.Run(() => { string command = $"sox {tempFile} -d"; ShllCommad(command); });
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "开始播放" + "\"}";
}
@ -1012,10 +1009,7 @@ namespace AksWebBrowser
{
if (ispaly)
{
Task.Run(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}";
SubmitLogs(result, "PalyFile");
return result;
@ -1024,37 +1018,33 @@ namespace AksWebBrowser
{
Task.Run(() =>
{
Task.Run(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
Uri uri = new Uri(url);
//返回 123.xlsx
var filename = HttpUtility.UrlDecode(uri.Segments.Last());
//获取文件后缀
string ext = System.IO.Path.GetExtension(filename);
DateTime dateTime = DateTime.Now;
string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = Utils.getSystemPaht() + @"/wwwroot/WaveOutFile";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
string path = dirpath + @"/" + time + ext;
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (FileStream fileStream = new FileStream(path, FileMode.Create))
{
stream.CopyTo(fileStream);
}
}
response.Close();
string command = $"pkill sox"; ShllCommad(command);
//Uri uri = new Uri(url);
////返回 123.xlsx
//var filename = HttpUtility.UrlDecode(uri.Segments.Last());
////获取文件后缀
//string ext = System.IO.Path.GetExtension(filename);
//DateTime dateTime = DateTime.Now;
//string time = DateTime.Now.ToString(
// "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
//string dirpath = Utils.getSystemPaht() + @"/wwwroot/WaveOutFile";
//if (!Directory.Exists(dirpath))
//{
// Directory.CreateDirectory(dirpath);
//}
//string path = dirpath + @"/" + time + ext;
//WebRequest request = WebRequest.Create(url);
//WebResponse response = request.GetResponse();
//using (Stream stream = response.GetResponseStream())
//{
// using (FileStream fileStream = new FileStream(path, FileMode.Create))
// {
// stream.CopyTo(fileStream);
// }
//}
//response.Close();
//开始播放
string command = $"sox {path} -d";
command = $"sox {url} -d";
ShllCommad(command);
//AutoAudio(ispaly, path);
});

Loading…
Cancel
Save