資源簡介
C#騰訊AI 接口簽名工具 語音合成demo
在工具類中有個完整的語音合成的Demo
繼之前的demo 做了一下修改,更加適合初學者使用。
具體接口文檔地址參照https://ai.qq.com/doc/aaitts.shtml
在demo中將標注的字段改為你自己注冊的相應字段即可,語音合成的demo就能跑起來,工具類和demo僅提供學習和參考使用,并不是所有的接口都是一樣的 ,所以本demo 和工具類希望能給開發者和各位同學提供一個思路,感謝,有問題留言提出!
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Security.Cryptography;
using?System.Text;
using?System.Web;
using?System.Net;
using?System.Net.Http;
using?System.IO;
namespace?AIweb
{
????///?
????///?騰訊AI智能接口調用工具類
????///?作者:APan
????///?官網:www.boeek.cn
????///?聲明:本工具類僅提供學習使用,若涉及商業用途必追究責任!
????///?
????///?工具類說明:
????///????????????
????///??????????????結合騰訊大部分AI接口,我已經將幾個通用的參數封裝到了方法中了,具體參數如下
????///??????????????你也可根據自己的需求更改對應的方法,達到更過多的功能,感謝你的支持!?????????????
????///?
????///?
????///??????????????time_stamp??請求時間戳(秒級)????????????????
????///??????????????nonce_str???隨機字符串
????///??????????????sign????????簽名??MD5加密鑒權
????///??????????????
????///??????????????以上三個參數不需要加入字典Dictionary
????///?
????public?class?AILab
????{
????????///?
????????///?獲取接口返回json數據
????????///?
????????///?字典
????????///?秘鑰
????????///?接口地址
????????///?請求類型
????????///?返回json
????????public?string??GetJsonData(Dictionary?PramaryArry?string?appkey?string?apiurlstring?HttpType)
????????{
????????????/*??這里需要注意一下?英文字母小寫在進行簽名計算時?會被全部轉換成大寫,
????????????????這樣就會和文本產生不一致,導致簽名錯誤,所以這個地方我同意將英文
????????????????全部轉換成了大寫避免簽名錯誤的問題出現,省去驗證,若需要自行更改
????????????????邏輯,思路僅供參考!??*/
????????????PramaryArry[“text“]?=?PramaryArry[“text“].ToUpper();
????????????string?time_stamp?=?((DateTime.Now.ToUniversalTime().Ticks?-?621355968000000000)?/?10000000).ToString();
????????????string?nonce_str?=?DateTime.Now.Ticks.ToString();
????????????PramaryArry.Add(“time_stamp“?time_stamp);
????????????PramaryArry.Add(“nonce_str“?nonce_str);
????????????//?計算sign參數(接口請求簽名)
????????????string?sign=?getReqSign(PramaryArryappkey);
????????????PramaryArry.Add(“sign“?sign);
????????????string?ret=““;
????????????if(HttpType.ToUpper()==“GET“)
????????????????
?????????????????ret?=?Get(apiurl?PramaryArry);
????????????else
?????????????????ret?=?Post(apiurl?PramaryArry);
????????????return?ret;
????????}
????????//計算簽名
????????private?string?getReqSign(Dictionary?d?string?appkey)
????????{
????????????//根據key?進行排序
???????????var???dd?=?d.OrderBy(p?=>?p.Key)?;
????????????//?2.?拼按URL鍵值對
????????????string??str?=?““;
????????????HttpContext?context?=?HttpContext.Current;
????????????foreach?(var?item?in?dd)
????????????{
????????????????str?+=?item.Key?+?‘=‘?+?context.Server.UrlEncode(item.Value).ToUpper()?+?“&“;
????????????}
????????????//拼接appkey
????????????str?+=“app_key=“+appkey;
????????????//md5編碼轉換
????????????MD5?md5?=?new?MD5CryptoServiceProvider();
????????????byte[]?strBuffer?=?System.Text.Encoding.UTF8.GetBytes(str);
????????????strBuffer?=?md5.ComputeHash(strBuffer?0?strBuffer.Length);
????????????str?=?BitConverter.ToStrin
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-06-01?16:30??AIweb\
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\AIweb\
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\AIweb\v15\
?????文件???????48128??2019-06-01?17:40??AIweb\.vs\AIweb\v15\.suo
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\AIweb\v15\Server\
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\AIweb\v15\Server\sqlite3\
?????文件???????????0??2019-06-01?16:30??AIweb\.vs\AIweb\v15\Server\sqlite3\db.lock
?????文件??????970752??2019-06-01?17:08??AIweb\.vs\AIweb\v15\Server\sqlite3\storage.ide
?????文件???????32768??2019-06-01?16:30??AIweb\.vs\AIweb\v15\Server\sqlite3\storage.ide-shm
?????文件?????4120032??2019-06-01?17:40??AIweb\.vs\AIweb\v15\Server\sqlite3\storage.ide-wal
?????目錄???????????0??2019-06-01?16:30??AIweb\.vs\config\
?????文件???????85788??2019-06-01?16:30??AIweb\.vs\config\applicationhost.config
?????目錄???????????0??2019-06-01?17:39??AIweb\AIweb\
?????文件?????????905??2018-05-24?22:23??AIweb\AIweb.sln
?????文件???????48128??2018-08-02?11:03??AIweb\AIweb.v11.suo
?????文件????????7664??2019-06-01?17:24??AIweb\AIweb\AILab.cs
?????文件????????5255??2018-05-24?23:10??AIweb\AIweb\AIweb.csproj
?????文件????????1197??2019-06-01?16:33??AIweb\AIweb\AIweb.csproj.user
?????目錄???????????0??2019-06-01?16:33??AIweb\AIweb\bin\
?????文件???????10752??2019-06-01?17:36??AIweb\AIweb\bin\AIweb.dll
?????文件?????????356??2018-05-24?22:23??AIweb\AIweb\bin\AIweb.dll.config
?????文件???????19968??2019-06-01?17:36??AIweb\AIweb\bin\AIweb.pdb
?????目錄???????????0??2019-06-01?17:39??AIweb\AIweb\mp3\
?????文件???????10800??2019-06-01?17:34??AIweb\AIweb\mp3\123123.mp3
?????文件????????8784??2019-06-01?17:39??AIweb\AIweb\mp3\四大皆空.mp3
?????文件????????7920??2019-06-01?17:36??AIweb\AIweb\mp3\大蘋果.mp3
?????文件????????8208??2019-06-01?17:36??AIweb\AIweb\mp3\小蘋果.mp3
?????文件???????13968??2019-06-01?17:38??AIweb\AIweb\mp3\曹貴你是不是傻?啊?啊?啊.mp3
?????文件???????11952??2019-06-01?17:37??AIweb\AIweb\mp3\曹貴你是不是傻.mp3
?????目錄???????????0??2018-05-28?09:10??AIweb\AIweb\obj\
............此處省略19個文件信息
- 上一篇:C#實現自動升級程序含客戶端和服務端
- 下一篇:C#串口上位機界面。帶緩沖區的
評論
共有 條評論