1. 程式人生 > >調用 Windows 7 中英文混合朗讀

調用 Windows 7 中英文混合朗讀

chinese 調用 .cn bsp cnblogs .dll files dial lte

1、windows7內置語音識別

2、文本到語音轉換增加了 Microsoft Lili - Chinese(China) ,支持中英文混合朗讀

3、女聲、部分詞組基本發音準確

以上讓我有做個小程序的沖動;如下:

1、引入SpeechLib.dll

2、創建form

3、編寫代碼

技術分享
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}

private void FormMain_Load(object sender, EventArgs e)
{
GetVoices();
}

private void GetVoices()
{
SpVoice voice
= new SpVoiceClass();
ISpeechObjectTokens voices
= voice.GetVoices("", "");
var list
= new List<string>();
foreach (ISpeechObjectToken token in voices)
list.Add(token.GetDescription(
0));
cbSpeechType.DataSource
= list;
}

private void btnSpeechText_Click(object sender, EventArgs e)
{
SpeechText(
null);
}

private void SpeechText(string fileName)
{
Cursor
= Cursors.WaitCursor;
SpFileStream stream
= null;
SpVoice voice
= new SpVoiceClass();
if (fileName + "" != "")
{
stream
= new SpFileStreamClass();
stream.Open(fileName, SpeechStreamFileMode.SSFMCreateForWrite,
false);
voice.AudioOutputStream
= stream;
}
voice.Voice
= voice.GetVoices("", "").Item(cbSpeechType.SelectedIndex);
voice.Volume
= tbVol.Value;
voice.Rate
= tbSpeechSpeed.Value;
voice.Speak(tbText.Text, SpeechVoiceSpeakFlags.SVSFDefault);
if (fileName + "" != "" && stream != null)
stream.Close();
Cursor
= Cursors.Arrow;
}

private void btnRecordSpeech_Click(object sender, EventArgs e)
{
Cursor
= Cursors.WaitCursor;
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.FileName
= "MyVoice.wav";
saveFileDialog.Filter
= "Wave (*.wav)|*.wav";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
SpeechText(saveFileDialog.FileName);
}
}
Cursor
= Cursors.Arrow;
}
}
技術分享

以上功能支持朗讀文本框內文本,支持講文本輸出語音文件;

參考應用場景:

1、嘗嘗鮮,再刪除

2、將小說文本轉化為音頻放MP3內去聽

3、騙騙小孩

運行環境需求:

1、WINDOWS 7

2、其他未知

說再多不如放個代碼,所以本文從簡,請下載後編譯運行。

AnySpeech.rar

出處:http://www.cnblogs.com/Chinasf/archive/2010/01/04/1639282.html

調用 Windows 7 中英文混合朗讀