|
|
|
@ -1,26 +1,14 @@
|
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using AKS.EnterpriseLibrary.WebBrowser; |
|
|
|
|
using AksWebBrowser.Devices; |
|
|
|
|
using AKSWebBrowser.Commen; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Globalization; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Net.Http; |
|
|
|
|
using System.Net.Http.Headers; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using CPF.Controls; |
|
|
|
|
using AKSWebBrowser.Commen; |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Net.NetworkInformation; |
|
|
|
|
using AKS.EnterpriseLibrary.WebBrowser; |
|
|
|
|
using System.Globalization; |
|
|
|
|
using CPF; |
|
|
|
|
using CPF.Windows; |
|
|
|
|
using static System.Net.Mime.MediaTypeNames; |
|
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
using AksWebBrowser.Devices; |
|
|
|
|
using LibVLCSharp.Shared; |
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
namespace AksWebBrowser.Common |
|
|
|
|
{ |
|
|
|
@ -221,42 +209,97 @@ namespace AksWebBrowser.Common
|
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var client = new HttpClient(); |
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); |
|
|
|
|
var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \"" + tts_text + "\"\r\n }\r\n }\r\n }", null, "application/json"); |
|
|
|
|
request.Content = content; |
|
|
|
|
var response = await client.SendAsync(request); |
|
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
|
if (response.StatusCode.ToString() == "OK") |
|
|
|
|
if (tts_text.Length <= 2000) |
|
|
|
|
{ |
|
|
|
|
// 读取响应内容 |
|
|
|
|
string body = await response.Content.ReadAsStringAsync(); |
|
|
|
|
// Log.Info("文字转语音:" + body); |
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
|
|
|
string ret = jo["ret_info"].ToString(); |
|
|
|
|
JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); |
|
|
|
|
if (jo2["code"].ToString() == "0") |
|
|
|
|
var client = new HttpClient(); |
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); |
|
|
|
|
var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \"" + tts_text + "\"\r\n }\r\n }\r\n }", null, "application/json"); |
|
|
|
|
request.Content = content; |
|
|
|
|
var response = await client.SendAsync(request); |
|
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
|
if (response.StatusCode.ToString() == "OK") |
|
|
|
|
{ |
|
|
|
|
//读取data数据 |
|
|
|
|
//读取data数据 |
|
|
|
|
string data = jo["data"].ToString(); |
|
|
|
|
JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); |
|
|
|
|
//读取parameters数据 |
|
|
|
|
string parameters = jo3["parameters"].ToString(); |
|
|
|
|
JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); |
|
|
|
|
//读取签字base64 |
|
|
|
|
string sound_path = jo4["sound_path"].ToString(); |
|
|
|
|
return sound_path; |
|
|
|
|
// 读取响应内容 |
|
|
|
|
string body = await response.Content.ReadAsStringAsync(); |
|
|
|
|
// Log.Info("文字转语音:" + body); |
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
|
|
|
string ret = jo["ret_info"].ToString(); |
|
|
|
|
JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); |
|
|
|
|
if (jo2["code"].ToString() == "0") |
|
|
|
|
{ |
|
|
|
|
//读取data数据 |
|
|
|
|
//读取data数据 |
|
|
|
|
string data = jo["data"].ToString(); |
|
|
|
|
JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); |
|
|
|
|
//读取parameters数据 |
|
|
|
|
string parameters = jo3["parameters"].ToString(); |
|
|
|
|
JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); |
|
|
|
|
//返回文件路径 |
|
|
|
|
string sound_path = jo4["sound_path"].ToString(); |
|
|
|
|
return sound_path; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//Log.Error("请求签字失败" + jo["message"].ToString()); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//Log.Error("请求签字失败" + jo["message"].ToString()); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return ""; |
|
|
|
|
int segmentLength = 2000; |
|
|
|
|
string[] segments = Utils.SplitTextIntoSegments(tts_text, segmentLength); |
|
|
|
|
List<string> lit = new List<string>(); |
|
|
|
|
string _tmp = string.Empty; |
|
|
|
|
foreach (string segment in segments) |
|
|
|
|
{ |
|
|
|
|
var client = new HttpClient(); |
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); |
|
|
|
|
var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \"" + segment + "\"\r\n }\r\n }\r\n }", null, "application/json"); |
|
|
|
|
request.Content = content; |
|
|
|
|
var response = await client.SendAsync(request); |
|
|
|
|
response.EnsureSuccessStatusCode(); |
|
|
|
|
if (response.StatusCode.ToString() == "OK") |
|
|
|
|
{ |
|
|
|
|
// 读取响应内容 |
|
|
|
|
string body = await response.Content.ReadAsStringAsync(); |
|
|
|
|
// Log.Info("文字转语音:" + body); |
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
|
|
|
string ret = jo["ret_info"].ToString(); |
|
|
|
|
JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); |
|
|
|
|
if (jo2["code"].ToString() == "0") |
|
|
|
|
{ |
|
|
|
|
//读取data数据 |
|
|
|
|
//读取data数据 |
|
|
|
|
string data = jo["data"].ToString(); |
|
|
|
|
JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); |
|
|
|
|
//读取parameters数据 |
|
|
|
|
string parameters = jo3["parameters"].ToString(); |
|
|
|
|
JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); |
|
|
|
|
//返回文件路径 |
|
|
|
|
string sound_path = jo4["sound_path"].ToString(); |
|
|
|
|
lit.Add(sound_path); |
|
|
|
|
_tmp = _tmp + " " + sound_path + " "; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (lit.Count == segments.Length) |
|
|
|
|
{ |
|
|
|
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
|
|
string path = $"/tmp/{time}.wav"; |
|
|
|
|
string command = $"sox {_tmp} -m {path}"; |
|
|
|
|
MainModel.ShllCommad(command); |
|
|
|
|
return path; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|