資源簡介
.NET開發的一個Demo接口,實現功能:tts/語音生成/文本轉語音,調用科大訊飛接口,需要替換自己的msc.dll和appID以及文件上傳的服務器地址
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Configuration;
using?System.IO;
using?System.Linq;
using?System.Net;
using?System.Text;
using?System.Web;
namespace?tts
{
????///?
????///?text?的摘要說明
????///?
????public?class?text2audio?:?IHttpHandler
????{
????????public?void?ProcessRequest(HttpContext?context)
????????{
????????????context.Response.ContentType?=?“text/plain“;
????????????string?text?=?context.Request.Form[“text“];
????????????//string?text?=?context.Request.QueryString[“text“];
????????????//string?text?=?“test測試音頻“;
????????????//string?path?=?“D:/audios/temp/audioTest23334455.pcm“;
????????????//保存文件路徑(絕對路徑)
????????????string?catalog?=?DateTime.Now.ToString(“yyyyMMdd“);
????????????string?filePath?=?System.IO.Path.Combine(GetConfigValue(“AudioAbsoluteFolderTemp“)?catalog);
????????????if?(!System.IO.Directory.Exists(filePath))
????????????{
????????????????System.IO.Directory.CreateDirectory(filePath);
????????????}
????????????string?audioName?=?CreateFileName(“.wav“);
????????????string?audioPath?=?System.IO.Path.Combine(filePath??audioName);
????????????//發音人
????????????if?(context.Request.Form[“speeker“]?!=?null)
????????????{
????????????????int?speekerIndex?=?int.Parse(context.Request.Form[“speeker“]);
????????????????string?speeker?=?““;
????????????????switch?(speekerIndex)
????????????????{
????????????????????case?0:
????????????????????????speeker?=?“xiaoyan“;
????????????????????????break;
????????????????????case?1:
????????????????????????speeker?=?“aisjiuxu“;
????????????????????????break;
????????????????????case?2:
????????????????????????speeker?=?“aisxping“;
????????????????????????break;
????????????????????case?3:
????????????????????????speeker?=?“aisjinger“;
????????????????????????break;
????????????????????case?4:
????????????????????????speeker?=?“aisbabyxu“;
????????????????????????break;
????????????????????default:
????????????????????????speeker?=?“xiaoyan“;
????????????????????????break;
????????????????}
????????????????Text2Audio(text?audioPath?speeker);
????????????}
????????????else
????????????{
????????????????Text2Audio(text?audioPath);
????????????}
????????????//獲取(相對路徑)
????????????string?relativeUrl?=?GetConfigValue(“AudioRelativeFolderTemp“);
????????????string?returnURL?=?System.IO.Path.Combine(relativeUrl?catalog?audioName).Replace(“\\“?“/“);
????????????//返回到Response里
????????????context.Response.Write(returnURL);
????????}
????????public?static?String?Md5(string?s)
????????{
????????????System.Security.Cryptography.MD5?md5?=?new?System.Security.Cryptography.MD5CryptoServiceProvider();
????????????byte[]?bytes?=?System.Text.Encoding.UTF8.GetBytes(s);
????????????bytes?=?md5.ComputeHash(bytes);
????????????md5.Clear();
????????????string?ret?=?““;
????????????for?(int?i?=?0;?i?????????????{
????????????????ret?+=?Convert.ToStri
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????85773??2019-08-06?11:26??tts\.vs\config\applicationhost.config
????..A..H.?????48128??2019-08-16?11:09??tts\.vs\tts\v15\.suo
?????文件??????????0??2019-08-06?11:26??tts\.vs\tts\v15\Server\sqlite3\db.lock
?????文件?????733184??2019-08-06?21:09??tts\.vs\tts\v15\Server\sqlite3\storage.ide
?????文件??????32768??2019-08-16?10:50??tts\.vs\tts\v15\Server\sqlite3\storage.ide-shm
?????文件????4124152??2019-08-07?08:48??tts\.vs\tts\v15\Server\sqlite3\storage.ide-wal
?????文件???????9355??2018-05-24?16:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\.signature.p7s
?????文件????????271??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props
?????文件???????5530??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props
?????文件????????275??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props
?????文件???????5530??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props
?????文件???????2421??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\app.config.install.xdt
?????文件????????994??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\app.config.uninstall.xdt
?????文件???????2131??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\web.config.install.xdt
?????文件????????742??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\web.config.uninstall.xdt
?????文件???????2432??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\app.config.install.xdt
?????文件????????994??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\app.config.uninstall.xdt
?????文件???????2142??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\web.config.install.xdt
?????文件????????742??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\web.config.uninstall.xdt
?????文件??????40080??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
?????文件???????1805??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xm
?????文件???13116405??2019-08-06?11:27??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0.nupkg
?????文件??????15976??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\net45\install.ps1
?????文件??????13832??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\net45\uninstall.ps1
?????文件??????50032??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\csc.exe
?????文件???????1711??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\csc.exe.config
?????文件???????1496??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\csc.rsp
?????文件??????13680??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\csi.exe
?????文件????????253??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\csi.rsp
?????文件?????105392??2018-05-24?13:38??tts\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\tools\Roslyn45\Microsoft.Build.Tasks.CodeAnalysis.dll
............此處省略169個文件信息
評論
共有 條評論