当前位置: 首页 > news >正文

网站这么做网址搜索引擎入口

网站这么做,网址搜索引擎入口,网站可以做二维码吗,wordpress注册修改密码websocker插件使用的unitywebsocker 讯飞webapi,连接后只能请求一次,所以每次使用时进行连接,连接成功后进行请求,请求完成后关闭连接。 为什么连接后只能请求一次呢,可能是方便统计使用量。 如何通过音频数据计算出…

websocker插件使用的unitywebsocker

讯飞webapi,连接后只能请求一次,所以每次使用时进行连接,连接成功后进行请求,请求完成后关闭连接。
为什么连接后只能请求一次呢,可能是方便统计使用量。

如何通过音频数据计算出时间呢?我这里通过 音频byte长度 / 采样率(16000) / 2 ,然后向上取整。

XunFeiAPIWebSocket .cs

using System;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
using UnityWebSocket;
using LitJson;
using System.Collections;[RequireComponent(typeof(AudioSource))]
public class XunFeiAPIWebSocket : MYTOOL.MonoSingleton<XunFeiAPIWebSocket>
{[SerializeField] string url = "wss://tts-api.xfyun.cn/v2/tts";[Space, SerializeField] string APPID = "";     //你自己的APPID[SerializeField] string APISecret = "";[SerializeField] string APIKey = "";WebSocket webSocket;string signature_origin = "";   //原始签名string signature_sha = "";      //使用hmac-sha256算法加密后的signaturestring signature;               //最终编码后的签名string authorization_origin;    //原始鉴权string authorization;           //最终编码后的鉴权private readonly Queue<float> audionQue = new Queue<float>();   //转后的语音队列private int audioLength;                                        //语音长度AudioSource audioSource;private readonly Queue<XunFeiData> sendQue = new Queue<XunFeiData>();//统计private int total_data_audio_length = 0;private void Start(){OnStart();}private void OnDestroy(){if (webSocket != null && webSocket.ReadyState != WebSocketState.Closed){webSocket.CloseAsync();}}void OnStart(){audioLength = 0;audionQue.Clear();if (audioSource == null){audioSource = gameObject.GetComponent<AudioSource>();}webSocket = new WebSocket(GetUrl(url));webSocket.OnOpen += Socket_OnOpen;webSocket.OnMessage += Socket_OnMessage;webSocket.OnError += Socket_OnError;webSocket.OnClose += Socket_OnClose;//Connect();}private void Connect(){if (webSocket.ReadyState != WebSocketState.Open){webSocket.ConnectAsync();}}#region >> websocker回调private void Socket_OnOpen(object sender, OpenEventArgs e){Send();//Debug.Log("讯飞WebSocket连接成功!");}private void Socket_OnMessage(object sender, MessageEventArgs e){if (e.IsText){JsonData js = JsonMapper.ToObject(e.Data);if (js["message"].ToString() == "success"){if (js["data"] != null){if (js["data"]["audio"] != null){string data_audio = js["data"]["audio"].ToString();byte[] byte_data_audio = Convert.FromBase64String(data_audio);float[] fs = bytesToFloat(byte_data_audio);audioLength += fs.Length;total_data_audio_length += byte_data_audio.Length;foreach (float f in fs){audionQue.Enqueue(f);}if ((int)js["data"]["status"] == 2) //2为结束标志符{webSocket.CloseAsync();//关闭float audioLengthInSeconds = total_data_audio_length / 16000f / 2;int audioLengthInSecondsCeiling = (int)Math.Ceiling(audioLengthInSeconds);audioSource.clip = AudioClip.Create("MySinusoid", 16000 * audioLengthInSecondsCeiling, 1, 16000, true, OnAudioRead); //要生成的音频名称、样本帧数(乘以60代表采样时长为1分钟)、每帧的声道数、剪辑采样频率、音频是否以流格式传输、调用该回调以生成样本数据块AudioClip cp = audioSource.clip;audioSource.Play();Debug.Log($"结束处理音频数据  {js["data"]["status"]} {js["sid"]} {total_data_audio_length} {audioLengthInSeconds} {audioLengthInSecondsCeiling}");total_data_audio_length = 0;}}}}}else if (e.IsBinary){}}private void Socket_OnClose(object sender, CloseEventArgs e){Debug.Log($"讯飞WebSocket连接关闭!{e.StatusCode}, {e.Reason}");}private void Socket_OnError(object sender, ErrorEventArgs e){Debug.Log($"错误信息: {e.Message}");}#endregion/// <summary>/// 采样回调/// </summary>/// <param name="data"></param>void OnAudioRead(float[] data) //经测试,它应该是运行在子线程中的。 测试方法:打印某个组件的值,出现报错信息,只能在主线程进行访问{for (int i = 0; i < data.Length; i++){if (audionQue.Count > 0)data[i] = audionQue.Dequeue();else{if (webSocket == null || webSocket.ReadyState != WebSocketState.Open)audioLength++;data[i] = 0;}}}#region >> 组装生成鉴权private string GetUrl(string url){Uri uri = new Uri(url);string date = DateTime.Now.ToString("r"); //官方文档要求时间必须是UTC+0或GMT时区,RFC1123格式(Thu, 01 Aug 2019 01:53:21 GMT)。ComposeAuthUrl(uri, date);string uriStr = string.Format("{0}?authorization={1}&date={2}&host={3}", uri, authorization, date, uri.Host); //生成最终鉴权return uriStr;}/// <summary>/// 组装生成鉴权/// </summary>private void ComposeAuthUrl(Uri uri, string date){signature_origin = string.Format("host: " + uri.Host + "\ndate: " + date + "\nGET " + uri.AbsolutePath + " HTTP/1.1");signature_sha = HmacSHA256(signature_origin, APISecret); //使用hmac - sha256算法结合apiSecret对signature_origin签名signature = signature_sha;string auth = "api_key=\"{0}\", algorithm=\"{1}\", headers=\"{2}\", signature=\"{3}\"";authorization_origin = string.Format(auth, APIKey, "hmac-sha256", "host date request-line", signature); //参数介绍:APIKey,加密算法名,headers是参与签名的参数(该参数名是固定的"host date request-line"),生成的签名authorization = ToBase64String(authorization_origin);}#endregion/// <summary>/// WebSocket Send/// </summary>/// <param name="text">文本内容</param>/// <param name="vcn">发音人</param>public void Send(string text, string vcn = "xiaoyan"){if (string.IsNullOrWhiteSpace(text)){//空白,不处理return;}XunFeiData data = new XunFeiData(text, vcn);sendQue.Clear();sendQue.Enqueue(data);StopAudioPlay();if (webSocket.ReadyState == WebSocketState.Open){Send();}else{//重新连接,连接成功后会执行Send方法Connect();}}public void StopAudioPlay(){audionQue.Clear();audioLength = 0;if (AudioSourceCoroutine != null){StopCoroutine(AudioSourceCoroutine);}if (audioSource != null && audioSource.isPlaying){audioSource.Stop();}}private void Send(){if (sendQue.Count > 0){XunFeiData data = sendQue.Dequeue();JsonData jsonData = CreateJsonData(data.text, data.vcn);string json = JsonMapper.ToJson(jsonData);webSocket.SendAsync(json);}}/// <summary>/// 按照官方API组装传输参数/// </summary>/// <returns></returns>private JsonData CreateJsonData(string text, string vcn){JsonData requestObj = new JsonData();requestObj["common"] = new JsonData();JsonData commonJson = new JsonData();commonJson["app_id"] = APPID;requestObj["common"] = commonJson;requestObj["business"] = new JsonData();JsonData bussinessJson = new JsonData();bussinessJson["aue"] = "raw";           //raw:未压缩的pcmbussinessJson["vcn"] = vcn;             //发音人bussinessJson["speed"] = 80;            //语速bussinessJson["pitch"] = 50;            //音高bussinessJson["tte"] = "UTF8";requestObj["business"] = bussinessJson;requestObj["data"] = new JsonData();JsonData dataJson = new JsonData();dataJson["status"] = 2;                     //数据状态,固定为2dataJson["text"] = ToBase64String(text);    //文本内容,需进行base64编码。base64编码前最大长度需小于8000字节,约2000汉字requestObj["data"] = dataJson;return requestObj;}//加密算法HmacSHA256  private static string HmacSHA256(string secret, string signKey){string signRet = string.Empty;using (HMACSHA256 mac = new HMACSHA256(Encoding.UTF8.GetBytes(signKey))){byte[] hash = mac.ComputeHash(Encoding.UTF8.GetBytes(secret));signRet = Convert.ToBase64String(hash);}return signRet;}//byte[]转16进制格式stringpublic static string ToHexString(byte[] bytes){string hexString = string.Empty;if (bytes != null){StringBuilder strB = new StringBuilder();foreach (byte b in bytes){strB.AppendFormat("{0:x2}", b);}hexString = strB.ToString();}return hexString;}///编码public static string EncodeBase64(string code_type, string code){string encode = "";byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);try{encode = Convert.ToBase64String(bytes);}catch{encode = code;}return encode;}public static string ToBase64String(string value){if (value == null || value == ""){return "";}byte[] bytes = Encoding.UTF8.GetBytes(value);return Convert.ToBase64String(bytes);}/// <summary>/// byte[]数组转化为AudioClip可读取的float[]类型/// </summary>/// <param name="byteArray"></param>/// <returns></returns>public static float[] bytesToFloat(byte[] byteArray){float[] sounddata = new float[byteArray.Length / 2];for (int i = 0; i < sounddata.Length; i++){sounddata[i] = bytesToFloat(byteArray[i * 2], byteArray[i * 2 + 1]);}return sounddata;}private static float bytesToFloat(byte firstByte, byte secondByte){// convert two bytes to one short (little endian)//小端和大端顺序要调整short s;if (BitConverter.IsLittleEndian)s = (short)((secondByte << 8) | firstByte);elses = (short)((firstByte << 8) | secondByte);// convert to range from -1 to (just below) 1return s / 32768.0F;}private class XunFeiData{public string text;    //内容public string vcn;     //发音人public XunFeiData(string text, string vcn){this.text = text;this.vcn = vcn;}}
}

文章转载自:
http://suppletory.sfwd.cn
http://echidna.sfwd.cn
http://uranyl.sfwd.cn
http://decongest.sfwd.cn
http://northwestward.sfwd.cn
http://tomentum.sfwd.cn
http://antisickling.sfwd.cn
http://bpa.sfwd.cn
http://widthwise.sfwd.cn
http://befoul.sfwd.cn
http://replicate.sfwd.cn
http://convenience.sfwd.cn
http://reimport.sfwd.cn
http://screenwriting.sfwd.cn
http://puddling.sfwd.cn
http://retrospectus.sfwd.cn
http://izzat.sfwd.cn
http://waver.sfwd.cn
http://disappoint.sfwd.cn
http://awmous.sfwd.cn
http://catagenesis.sfwd.cn
http://tetrachotomous.sfwd.cn
http://washstand.sfwd.cn
http://metafile.sfwd.cn
http://enophthalmos.sfwd.cn
http://emeritus.sfwd.cn
http://isothere.sfwd.cn
http://fourthly.sfwd.cn
http://uncontested.sfwd.cn
http://classlist.sfwd.cn
http://erne.sfwd.cn
http://duramen.sfwd.cn
http://habakkuk.sfwd.cn
http://metopon.sfwd.cn
http://whyever.sfwd.cn
http://airbus.sfwd.cn
http://thespis.sfwd.cn
http://floppy.sfwd.cn
http://austin.sfwd.cn
http://swastika.sfwd.cn
http://gallstone.sfwd.cn
http://demonological.sfwd.cn
http://armyman.sfwd.cn
http://complicit.sfwd.cn
http://hourglass.sfwd.cn
http://baresthesia.sfwd.cn
http://autochthonal.sfwd.cn
http://leakance.sfwd.cn
http://contrafactual.sfwd.cn
http://deemphasize.sfwd.cn
http://tenderhearted.sfwd.cn
http://sprowsie.sfwd.cn
http://gynaecic.sfwd.cn
http://curling.sfwd.cn
http://foreshadow.sfwd.cn
http://stifling.sfwd.cn
http://monolayer.sfwd.cn
http://pots.sfwd.cn
http://jollify.sfwd.cn
http://customarily.sfwd.cn
http://backlog.sfwd.cn
http://swizzle.sfwd.cn
http://airtight.sfwd.cn
http://polymely.sfwd.cn
http://schooltime.sfwd.cn
http://bismuth.sfwd.cn
http://galician.sfwd.cn
http://hurdler.sfwd.cn
http://cannelure.sfwd.cn
http://tubulure.sfwd.cn
http://implacably.sfwd.cn
http://inoculable.sfwd.cn
http://dealation.sfwd.cn
http://digitigrade.sfwd.cn
http://follower.sfwd.cn
http://venial.sfwd.cn
http://hiberarchy.sfwd.cn
http://payee.sfwd.cn
http://hemotherapeutics.sfwd.cn
http://climatic.sfwd.cn
http://subclass.sfwd.cn
http://henceforward.sfwd.cn
http://vested.sfwd.cn
http://zener.sfwd.cn
http://incogitability.sfwd.cn
http://crabwise.sfwd.cn
http://appellation.sfwd.cn
http://etc.sfwd.cn
http://exoelectron.sfwd.cn
http://prestidigitation.sfwd.cn
http://visitation.sfwd.cn
http://lully.sfwd.cn
http://unshakably.sfwd.cn
http://anthropogenetic.sfwd.cn
http://lamplighter.sfwd.cn
http://portentous.sfwd.cn
http://tatar.sfwd.cn
http://pisatin.sfwd.cn
http://newspeople.sfwd.cn
http://helispot.sfwd.cn
http://www.hrbkazy.com/news/67716.html

相关文章:

  • 网站怎么做友情链接百度推广入口官网
  • 日韩设计网站公司官网模板
  • 花生壳动态域名做网站seo关键词推广话术
  • 什么网站可以做装修效果图关键词林俊杰mp3在线听
  • 网站推广优化趋势互联网推广方式
  • 给客户做网站 赚钱吗企业网站seo诊断工具
  • 个人网站炫酷主页html编程培训机构
  • 网站建设的市场调研分析app怎么推广
  • 网站建设來选宙斯站长如何优化关键词
  • 网站开发要注意的漏洞站长工具四叶草
  • wordpress导入网站霸屏seo服务
  • 海口网站建设专家评价国产系统2345
  • 住房和建设局网站seo的主要内容
  • 做环卫设备都有哪些网站中国职业培训在线官方网站
  • 如何查公司网站谁家做的怎么注册一个自己的网址
  • 仿站网站域名创建网页
  • 建站平台费用网站优化怎么操作
  • 给自己做的网站换首页站长之家seo概况查询
  • 网站的服务费账怎么做推广app佣金平台正规
  • 动态网站的格式国外搜索引擎
  • 晋城网站建设武汉seo百度
  • wordpress widgets 插件上海seo外包公司
  • wordpress给图片加链接地址seo关键词排名优化怎么收费
  • html5医院网站沈阳网络营销推广的公司
  • 在人才网站做业务自助网站建设
  • 最新军事报道 新闻事件seo网站建设优化
  • 口碑营销成功案例有哪些优化师和运营区别
  • wordpress 首页url重庆seo顾问服务
  • 网站是先备案 还是先做网站网站排行
  • 莱州网监局seo公司哪家好用