asp.net 中使用 微軟tts語音

來源:互聯網
上載者:User

實現平台:
Microsoft Visual Studio 2005
微軟TTS5.1語音引擎(中文)

所需要的東西:
用TlbImp從SAPI.51 SDK中匯出的點此下載DotNetSpeech.dll(160K)
微軟TTS5.1語音引擎(中文).msi(1.55M)以上兩個東西由於大小關係沒有傳上來,需要的可以留下郵箱地址。如果你自己安裝了SAPI.51 SDK,可以使用這個命令自己匯出DotNetSpeech.dll
Tlbimp sapi.dll /out: DotNetSpeech.dll(出現錯誤不用管,不影響使用)
安裝微軟TTS5.1語音引擎(中文).msi,開啟"控制台",開啟"語音"設定項目,在"文字-語音轉換"的"語音選擇"組合框中選擇"Microsoft Simplified Chinese",這樣才可以讀出中文。如果要讀英文,要選擇"Microsoft Sam"。

使用Microsoft Visual Studio 2005建立項目,添加引用,引用DotNetSpeech.dll。
命名空間:
using DotNetSpeech;

讀出文字框中的中文:
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
voice.Speak(textBox1.Text, spFlags);

將文字框中中文的讀音儲存為WAV檔案:
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
dialog.Title = "儲存WAV檔案";
dialog.FilterIndex = 2;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
SpeechStreamFileMode spFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream spFileStream = new SpFileStream();
spFileStream.Open(dialog.FileName, spFileMode, false);
voice.AudioOutputStream = spFileStream;
voice.Speak(textBox1.Text, spFlags);
voice.WaitUntilDone(1000);
上面兩句一定要寫上,否則產生的檔案沒有聲音
WaitUntilDone的後面的smTimeout是一個int型
spFileStream.Close();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.