@ -33,16 +33,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{
public class MainModel : CPF . CpfObject
{
public COMUtils com ;
public string callback = string . Empty ;
public string PrinterName = "Lexmark-MS430-Series" ;
public static Process recordingProcess ;
public static Process Typrocess ;
public TcpClients tcpClients = new TcpClients ( ) ;
public SignDll sign = new SignDll ( ) ;
public bool isStart = true ;
private string srpath = string . Empty ;
/// <summary>
/// 读取身份证卡号
/// 读取身份证卡号(已国产化)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
@ -67,7 +64,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 打印排队票据
/// 打印排队票据(已国产化)
/// </summary>
/// <param name="ph">排号</param>
/// <param name="ddrs">等待人数</param>
@ -112,7 +109,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 文字语音播报
/// 文字语音播报(已国产化)
/// apt install sox
/// apt install libsox-fmt-all
/// </summary>
@ -126,94 +123,47 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{
try
{
if ( isStart )
{
return "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "操作成功" + "\"}" ;
}
if ( ! isFuncisFuncObject ( "payleText" ) )
{
Utils . MessagesBox ( "文字语音播报设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}" ;
}
else if ( Parame . tcpClient = = null )
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}" ;
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}" ;
//Log.Info("文字语音播报: " + paramsString + "");
string base64 = str2Base64 ( paramsString ) ;
//if (base64.Length > 1024)
//{
// //形成临时文件
// DateTime dateTime = DateTime.Now;
// string time = DateTime.Now.ToString(
// "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
// var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "TempFile");
// if (!Directory.Exists(dirpath))
// {
// Directory.CreateDirectory(dirpath);
// }
// var filepath = System.IO.Path.Combine(dirpath, time);
// string path = dirpath + @"/" + time + ".txt";
// base64 = str2Base64(text);
// byte[] bytes = Convert.FromBase64String(base64);
// System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
// System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
// writer.Write(bytes, 0, bytes.Length);
// writer.Close();
// //Log.Info("文字语音播报临时文件: " + path + "");
// string id = Guid.NewGuid().ToString();
// //通过文件发送数据
// com.NewMethod(path, ".txt");
// //正式执行命令
// string url = "http://192.168.0.34:92/api/UploadFP/UploadFP";
// Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)");
// MatchCollection mc = re.Matches(url);//获取的是一个数组
// string pdfurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath;
// paramsString = "{\"callback\":\"" + callback + "\",\"bsid\":\"" + id + "\",\"type\":\"3\",\"param\":{\"text\":\"" + pdfurl + "\",\"ispaye\":\"" + ispaye + "\"}}";
// //Log.Info("文字语音播报: " + paramsString + "");
// base64 = str2Base64(paramsString);
//}
string str = tcpClients . SendDataWithHeader ( Parame . tcpClient . GetStream ( ) , base64 ) ;
return Base64str2 ( str ) ;
//if (ispaye)
//{
// Task.Run(() =>
// {
// if (Typrocess != null)
// {
// // 如果进程还在运行
// if (!Typrocess.HasExited)
// {
// // 发送SIGTERM信号来停止进程
// Typrocess.Kill();
// // 等待进程真正停止
// Typrocess.WaitForExit();
// }
// }
// });
// string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}";
// SubmitLogs(result, "payleText");
// return result;
//}
//else
//{
// Task.Run(() =>
// {
// //形成语音
// tempWav = GenerateWavFromText(text);
// //开始播放
// string command = $"sox {tempWav} -d";
// ShllCommad(command);
// });
// string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}";
// SubmitLogs(result, "payleText");
// return result;
//}
if ( ispaye )
{
Task . Run ( ( ) = >
{
if ( Typrocess ! = null )
{
// 如果进程还在运行
if ( ! Typrocess . HasExited )
{
// 发送SIGTERM信号来停止进程
Typrocess . Kill ( ) ;
// 等待进程真正停止
Typrocess . WaitForExit ( ) ;
}
}
} ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}" ;
SubmitLogs ( result , "payleText" ) ;
return result ;
}
else
{
Task . Run ( ( ) = >
{
//形成语音
tempWav = GenerateWavFromText ( text ) ;
//开始播放
string command = $"sox {tempWav} -d" ;
ShllCommad ( command ) ;
} ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}" ;
SubmitLogs ( result , "payleText" ) ;
return result ;
}
}
}
catch ( Exception ex )
@ -226,51 +176,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 发送短信
/// </summary>
/// <param name="content"></param>
/// <param name="phone"></param>
/// <returns></returns>
[JSFunction]
public string SendSSM ( string content , string phone )
{
try
{
if ( isStart )
{
return "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "操作成功" + "\"}" ;
}
if ( ! isFuncisFuncObject ( "SendSSM" ) )
{
Utils . MessagesBox ( "发送短信设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "发送短信设备未授权使用" + "\"}" ;
}
else if ( Parame . tcpClient = = null )
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}" ;
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}" ;
//Log.Info("发送短信: " + paramsString + "");
string base64 = str2Base64 ( paramsString ) ;
string str = tcpClients . SendDataWithHeader ( Parame . tcpClient . GetStream ( ) , base64 ) ;
string result = Base64str2 ( str ) ;
SubmitLogs ( result , "SendSSM" ) ;
return result ;
}
}
catch ( Exception ex )
{
Log . Error ( "发送短信异常: " + ex . Message + "" ) ;
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex . Message + "\"}" ;
SubmitLogs ( result , "SendSSM" ) ;
return result ;
}
}
/// <summary>
/// 打开高拍仪并且进行快速扫描文件
/// 打开高拍仪并且进行快速扫描文件 (已国产化)
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
@ -279,16 +185,18 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{
try
{
if ( isStart )
string devIndex = GetSnIndex ( ) ;
if ( string . IsNullOrEmpty ( devIndex ) )
{
return "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "操作成功" + "\"}" ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
return result ;
}
else
{
//获取设备信息
string devIndex = GetSnIndex ( ) ;
if ( string . IsNullOrEmpty ( devIndex ) )
//打开高拍仪
string param = OpenSn ( devIndex ) ;
if ( string . IsNullOrEmpty ( param ) )
{
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
@ -296,37 +204,26 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
else
{
//打开高拍仪
string param = OpenSn ( devIndex ) ;
//拍照
param = getFrame ( ) ;
if ( string . IsNullOrEmpty ( param ) )
{
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开 失败" + "\"}" ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片 失败" + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
return result ;
}
else
{
//拍照
param = getFrame ( ) ;
if ( string . IsNullOrEmpty ( param ) )
{
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
return result ;
}
else
Task . Run ( ( ) = >
{
Task . Run ( ( ) = >
{
//关闭
StopSn ( devIndex ) ;
} ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
return result ;
}
//关闭
StopSn ( devIndex ) ;
} ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}" ;
SubmitLogs ( result , "openCamera" ) ;
return result ;
}
}
}
}
@ -340,7 +237,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 打开签字版 sudo apt-get install libgdiplus
/// 打开签字版 sudo apt-get install libgdiplus (已国产化)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
@ -372,78 +269,72 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 指纹
/// 关闭签字版 (已国产化)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
[JSFunction]
public string Finger ( string paramsString , string callback )
public string CloseSign ( string paramsString )
{
try
{
if ( false ) //!isFuncisFuncObject("Finger" )
if ( ! isFuncisFuncObject ( "OpenSign" ) )
{
Utils . MessagesBox ( "指纹 设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹 设备未授权使用" + "\"}" ;
Utils . MessagesBox ( "签字版 设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版 设备未授权使用" + "\"}" ;
}
else
{
string result = Fingerprint . LIVESCANFinger ( callback ) ;
SubmitLogs ( result , "Finger" ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "成功" + "\"}" ;
SubmitLogs ( result , "OpenSign" ) ;
return result ;
}
}
catch ( Exception ex )
{
Log . Error ( "指纹 异常: " + ex . Message + "" ) ;
Log . Error ( "关闭签字版 异常: " + ex . Message + "" ) ;
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex . Message + "\"}" ;
SubmitLogs ( result , "Finger " ) ;
SubmitLogs ( result , "OpenSign " ) ;
return result ;
}
}
/// <summary>
/// 关闭签字版
/// 指纹 (已国产化,未完成测试)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
[JSFunction]
public string CloseSign ( string paramsString )
public string ReadFingerData ( string callback )
{
try
{
if ( ! isFuncisFuncObject ( "OpenSign" ) )
if ( false ) //!isFuncisFuncObject("Finger" )
{
Utils . MessagesBox ( "签字版 设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版 设备未授权使用" + "\"}" ;
Utils . MessagesBox ( "指纹 设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹 设备未授权使用" + "\"}" ;
}
else
{
//paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}";
////Log.Info("关闭签字版: " + paramsString + "");
//string base64 = str2Base64(paramsString);
//string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
//string result = Base64str2(str);
//SubmitLogs(result, "OpenSign");
//return result;
sign . ReleaseComDevice ( ) ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "成功" + "\"}" ;
SubmitLogs ( result , "OpenSign" ) ;
string result = Fingerprint . LIVESCANFinger ( callback ) ;
SubmitLogs ( result , "Finger" ) ;
return result ;
}
}
catch ( Exception ex )
{
Log . Error ( "关闭签字版 异常: " + ex . Message + "" ) ;
Log . Error ( "指纹异常: " + ex . Message + "" ) ;
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex . Message + "\"}" ;
SubmitLogs ( result , "OpenSign " ) ;
SubmitLogs ( result , "Finger " ) ;
return result ;
}
}
/// <summary>
/// 开始录音、取消录音、结束录音
/// 开始录音、取消录音、结束录音 (已国产化)
/// sudo apt-get update
/// sudo apt-get install alsa-utils
/// </summary>
@ -455,67 +346,69 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{
try
{
if ( isStart )
{
return "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "操作成功" + "\"}" ;
}
if ( ! isFuncisFuncObject ( "SoundRecording" ) )
{
Utils . MessagesBox ( "录音设备未授权使用" ) ;
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}" ;
}
else if ( Parame . tcpClient = = null )
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}" ;
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"11\",\"param\":{\"isopen\":\"" + isopen + "\",\"url\":\"" + url + "\"}}" ;
//Log.Info("开始录音、取消录音、结束录音: " + paramsString + "");
string base64 = str2Base64 ( paramsString ) ;
string str = tcpClients . SendDataWithHeader ( Parame . tcpClient . GetStream ( ) , base64 ) ;
//结束录音上传文件
if ( ! string . IsNullOrEmpty ( url ) & & ! isopen )
{
string tt = Base64str2 ( str ) ;
//Log.Info("结束录音上传文件" + tt);
//下载文件
DateTime dateTime = DateTime . Now ;
string time = DateTime . Now . ToString (
"yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) ;
var dirpath = System . IO . Path . Combine ( Environment . CurrentDirectory , "wwwroot" , "RecordFile" ) ;
if ( ! Directory . Exists ( dirpath ) )
if ( StopRecording ( ) )
{
Directory . CreateDirectory ( dirpath ) ;
Task . Run ( async ( ) = >
{
UploadInfo ( url , srpath ) ;
} ) ;
@event2 . WaitOne ( ) ;
Regex re = new Regex ( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)" ) ;
MatchCollection mc = re . Matches ( url ) ; //获取的是一个数组
string reurl = mc [ 0 ] . ToString ( ) + "://" + mc [ 1 ] . ToString ( ) + urlpath ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
var filepath = System . IO . Path . Combine ( dirpath , time ) ;
string path = dirpath + @"/" + time + ".wav" ;
WebRequest request = WebRequest . Create ( tt ) ;
WebResponse response = request . GetResponse ( ) ;
using ( Stream stream = response . GetResponseStream ( ) )
else
{
using ( FileStream fileStream = new FileStream ( path , FileMode . Create ) )
{
stream . CopyTo ( fileStream ) ;
}
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
response . Close ( ) ;
//上传文件
Task . Run ( async ( ) = > { UploadInfo ( url , path ) ; } ) ;
@event2 . WaitOne ( ) ;
Regex re = new Regex ( @"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)" ) ;
MatchCollection mc = re . Matches ( url ) ; //获取的是一个数组
string wavurl = mc [ 0 ] . ToString ( ) + "://" + mc [ 1 ] . ToString ( ) + urlpath ;
string result = "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + wavurl + "\"}" ;
//Log.Info(result);
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
else
else if ( isopen ) //开始录音
{
string result = Base64str2 ( str ) ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
if ( StartRecording ( ) )
{
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
else
{
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
}
else //取消录音
{
if ( StopRecording ( ) )
{
srpath = string . Empty ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
else
{
srpath = string . Empty ;
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}" ;
SubmitLogs ( result , "SoundRecording" ) ;
return result ;
}
}
}
}
@ -529,7 +422,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 根据文件地址在线打印
/// 根据文件地址在线打印 (已国产化)
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
@ -587,7 +480,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 根据文件base64打印
/// 根据文件base64打印 (已国产化)
/// </summary>
/// <param name="base64"></param>
/// <param name="ext"></param>
@ -625,26 +518,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string command = $"lp -d {PrinterName} {path}" ;
ShllCommad ( command ) ;
} ) ;
//string id = Guid.NewGuid().ToString();
////通过文件发送数据
//com.NewMethod(path, ext);
//Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#? (?:[\w]*))?)");
//MatchCollection mc = re.Matches(url);//获取的是一个数组
//string pdfurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath;
//Log.Info("根据文件base64打印: " + pdfurl + "");
//try
//{
// string paramsString = "{\"callback\":\"" + callback + "\",\"bsid\":\"" + id + "\",\"type\":\"9\",\"param\":{\"url\":\"" + pdfurl + "\",\"ext\":\"" + ext + "\"}}";
// //Log.Info("根据文件base64打印: " + paramsString + "");
// string base64_1 = str2Base64(paramsString);
// string str = com.SendData(base64_1, callback);
// return Base64str2(str);
//}
//catch (Exception ex)
//{
// Log.Error("根据文件base64打印异常: " + ex.Message + "");
// return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
//}
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}" ;
SubmitLogs ( result , "PrintBase64" ) ;
return result ;
@ -658,8 +531,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
}
/// <summary>
/// 播放音频文件
/// <summary>
/// 播放音频文件 (已国产化)
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
@ -749,60 +622,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
}
/// <summary>
/// 播放音频公共方法
/// </summary>
/// <param name="url"></param>
private void NewMethod ( string url )
{
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 ) ;
var dirpath = System . IO . Path . Combine ( Environment . CurrentDirectory , "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 ( WaveOutPath , FileMode . Create ) )
{
stream . CopyTo ( fileStream ) ;
}
}
response . Close ( ) ;
using ( player = new WaveOutEvent ( ) )
{
player . PlaybackStopped + = waveOut_PlaybackStopped ;
using ( audioFileReader = new AudioFileReader ( WaveOutPath ) )
{
// 创建一个增益效果器对象
var volumeProvider = new VolumeSampleProvider ( audioFileReader . ToSampleProvider ( ) ) ;
// 将音频文件添加到WaveOutEvent对象中
player . Init ( volumeProvider ) ;
// 设置音量增益为2倍
volumeProvider . Volume = 2.0f ;
// 开始播放音频
player . Play ( ) ;
while ( player . PlaybackState = = PlaybackState . Playing )
{
Thread . Sleep ( 1 0 0 0 ) ;
}
}
}
//Log.Info("开始播放");
}
/// <summary>
/// 播放完成
/// </summary>
@ -827,7 +646,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
/// <summary>
/// 唤醒键盘
/// 唤醒键盘 (已国产化)
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
@ -1080,7 +899,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
@event6 . Set ( ) ;
}
/// <summary>
/// 签字版
/// </summary>
@ -1155,12 +973,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
}
//关闭串口
public void CLoseCOM ( )
{
com . ClosePort ( ) ;
}
/// <summary>
/// 开始录音
/// </summary>
@ -1236,97 +1048,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
}
public static WaveFileWriter writer ;
public static StreamWriter mStreamWriter ;
public static WaveInEvent waveIn = null ;
private string srpath = string . Empty ;
//开启录音
private bool StateSoundRecor ( )
{
if ( waveIn ! = null )
{
waveIn . StopRecording ( ) ;
waveIn . Dispose ( ) ;
writer . Close ( ) ;
mStreamWriter . Close ( ) ;
waveIn = null ;
}
// 录音对象
waveIn = new WaveInEvent ( ) ;
int sampleRate = 4 8 0 0 0 ; //采样率
int channels = 2 ; //录音通道数
int bitsPerSample = 1 6 ; //位深
WaveFormat waveFormat = new WaveFormat ( sampleRate , bitsPerSample , channels ) ;
waveIn . WaveFormat = waveFormat ; //设置录音格式
DateTime dateTime = DateTime . Now ;
string time = DateTime . Now . ToString (
"yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) ;
var dirpath = System . IO . Path . Combine ( Environment . CurrentDirectory , "wwwroot" , "Record" ) ;
if ( ! Directory . Exists ( dirpath ) )
{
Directory . CreateDirectory ( dirpath ) ;
}
srpath = dirpath + "/" + time + ".wav" ;
string pathfile = dirpath + "/" + time + ".txt" ;
// 创建WaveFileWriter对象来保存录音数据 路径在bin文件下
writer = new WaveFileWriter ( srpath , waveFormat ) ;
//编写器
mStreamWriter = new StreamWriter ( pathfile , false , new System . Text . UTF8Encoding ( false ) ) ;
// 设置录音回调函数
int bitIndex = bitsPerSample / 8 ;
waveIn . DataAvailable + = ( sender , e ) = >
{
// 将录音数据写入文件
writer . Write ( e . Buffer , 0 , e . BytesRecorded ) ;
for ( int i = 0 ; i < e . BytesRecorded / bitIndex ; i + + )
{
//24bit,导出的数据
//int sample = (int)((e.Buffer[i * bitIndex + 2] << 16) | (e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]);
//16bit 将两个byte数据组合成一个short数据
short sample = ( short ) ( ( e . Buffer [ i * bitIndex + 1 ] < < 8 ) | e . Buffer [ i * bitIndex ] ) ;
mStreamWriter . Write ( "{0}," , sample ) ;
}
} ;
try
{
//尝试打开录音设备,如果设备支持设置的WaveFormat,则能够成功打开
waveIn . StartRecording ( ) ;
return true ;
}
catch ( Exception ex )
{
//Log.Info("录音开启失败:" + ex.Message);
srpath = "" ;
return false ;
}
}
/// <summary>
/// 停止录音、取消录音
/// </summary>
/// <param name="isopen"></param>
private bool StopSoundRecor ( )
{
try
{
//停止录音
waveIn . StopRecording ( ) ;
waveIn . Dispose ( ) ;
writer . Close ( ) ;
mStreamWriter . Close ( ) ;
waveIn = null ;
return true ;
}
catch ( Exception ex )
{
//Log.Info("停止录音、取消录音失败:" + ex.Message);
srpath = "" ;
return false ;
}
}
/// <summary>
/// 执行命令
/// </summary>