資源簡介
通過.net提供的Microsoft Speech實現文字轉語音為Wav格式,通過擴展實現轉化為Mp3格式

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Diagnostics;
using?System.IO;
using?System.Linq;
using?System.Speech.Synthesis;
using?System.Text;
using?System.Threading.Tasks;
namespace?FrmTest
{
????class?Common
????{
????????#region?MyRegion?文字生成音頻文件并保存
????????///?
????????///?文字生成音頻文件并保存
????????///?
????????///?文字內容
????????///?文件名稱
????????public?bool?SaveWav(string?content?string?fileName?bool?isSaveMp3?=?false)
????????{
????????????bool?result?=?true;
????????????try
????????????{
????????????????//文件夾目錄
????????????????string?urlW?=?System.Windows.Forms.Application.StartupPath?+?“\\Musics“;
????????????????if?(!Directory.Exists(urlW))//是否存在
????????????????{
????????????????????Directory.CreateDirectory(urlW);
????????????????}
????????????????string?url?=?urlW?+?“\\“?+?fileName?+?“.wav“;
????????????????content?=?NumberToChinese(content);
????????????????using?(SpeechSynthesizer?speech?=?new?SpeechSynthesizer())
????????????????{
????????????????????speech.SelectVoice(“VW?Liang“);//選擇播放語音庫
????????????????????speech.Volume?=?100;
????????????????????speech.Rate?=?-2;
????????????????????speech.SetOutputToWaveFile(url);
????????????????????speech.Speak(content);
????????????????????speech.SetOutputToDefaultAudioDevice();
????????????????}
????????????????if?(isSaveMp3)
????????????????{
????????????????????ChangeMp3(urlW?fileName?url);
????????????????????//轉換完成刪除生成的wav格式的音頻
????????????????????//?File.Delete(url);
????????????????}
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????writeLogInfo(“保存錄音文件失敗“?“失敗原因:“?+?ex.Message);
????????????????result?=?false;
????????????}
????????????return?result;
????????}
????????#endregion
????????#region?MyRegion?朗讀文本
????????///?
????????///?朗讀文本
????????///?
????????///?
????????///?
????????public?bool?SpeackTxt(string?content)
????????{
????????????try
????????????{
????????????????content?=?NumberToChinese(content);
????????????????SpeechSynthesizer?ss?=?new?SpeechSynthesizer();
????????????????ss.Volume?=?100;???//音量
????????????????ss.Rate?=?-2;?????//頻率
????????????????ss.SelectVoice(“VW?Hui“);//選擇播放語音庫
????????????????ss.SpeakAsync(content);
????????????????return?true;
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????writeLogInfo(“朗讀文本:“?ex.Message);
????????????????return?false;
????????????}
????????}
????????#endregion
????????#region?Wav轉換Mp3格式
????????///?
????????///??Wav轉換Mp3格式
????????///?
????????///?文件目錄
????????///?文件名
????????///??Wav音頻路徑
????????///?
????????public?bool?ChangeMp3(string?urlW?string?fileName?string?urlWav)
??????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-04?10:29??語音Demo\
?????目錄???????????0??2018-04-04?10:29??語音Demo\FrmTest\
?????目錄???????????0??2018-04-04?10:31??語音Demo\FrmTest\FrmTest\
?????文件?????????911??2018-04-04?09:58??語音Demo\FrmTest\FrmTest.sln
?????文件???????29696??2018-04-04?10:34??語音Demo\FrmTest\FrmTest.v11.suo
?????文件?????????187??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\App.config
?????目錄???????????0??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\bin\
?????目錄???????????0??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\bin\Debug\
?????文件???????12800??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\bin\Debug\FrmTest.exe
?????文件?????????187??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\bin\Debug\FrmTest.exe.config
?????文件???????28160??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\bin\Debug\FrmTest.pdb
?????文件???????22984??2018-04-04?10:34??語音Demo\FrmTest\FrmTest\bin\Debug\FrmTest.vshost.exe
?????文件?????????187??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\bin\Debug\FrmTest.vshost.exe.config
?????文件??????581120??2017-10-30?10:43??語音Demo\FrmTest\FrmTest\bin\Debug\lame.exe
?????目錄???????????0??2018-04-04?10:29??語音Demo\FrmTest\FrmTest\bin\Debug\Log\
?????文件????????1820??2018-04-04?10:34??語音Demo\FrmTest\FrmTest\bin\Debug\Log\2018-04-04.txt
?????目錄???????????0??2018-04-04?10:30??語音Demo\FrmTest\FrmTest\bin\Debug\Musics\
?????文件??????692224??2017-11-21?16:09??語音Demo\FrmTest\FrmTest\bin\Debug\system.speech.dll
?????目錄???????????0??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\bin\Release\
?????文件????????7630??2018-04-04?10:27??語音Demo\FrmTest\FrmTest\Common.cs
?????文件????????2217??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\FrmMian.cs
?????文件????????3912??2018-04-04?10:24??語音Demo\FrmTest\FrmTest\FrmMian.Designer.cs
?????文件????????5817??2018-04-04?10:24??語音Demo\FrmTest\FrmTest\FrmMian.resx
?????文件????????3883??2018-04-04?10:31??語音Demo\FrmTest\FrmTest\FrmTest.csproj
?????文件??????581120??2017-10-30?10:43??語音Demo\FrmTest\FrmTest\lame.exe
?????目錄???????????0??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\obj\
?????目錄???????????0??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\obj\Debug\
?????文件?????????863??2018-04-04?09:58??語音Demo\FrmTest\FrmTest\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????7029??2018-04-04?10:31??語音Demo\FrmTest\FrmTest\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????????498??2018-04-04?10:34??語音Demo\FrmTest\FrmTest\obj\Debug\FrmTest.csproj.FileListAbsolute.txt
?????文件?????????977??2018-04-04?10:33??語音Demo\FrmTest\FrmTest\obj\Debug\FrmTest.csproj.GenerateResource.Cache
............此處省略18個文件信息
評論
共有 條評論