在文本框中输入文本,按speak/stop按钮,如无故障,即可通过声卡发出语音。
HelloSpeech_exe.rar
9.53KB
RAR
46次下载
运行以上程序前,请首先确保安装了.NET Framework 4.0运行库支持。
如果没有,到这里下载:
http://go.microsoft.com/fwlink/?LinkId=204533以及,按照操作系统的不同(32还是64位),到以下地址下载 MS Speech Platform Runtime 11 并安装:
http://go.microsoft.com/fwlink/?LinkID=223568&clcid=0x409程序界面中的combobox1列表会包含本机安装的所有的语音合成数据包,供用户选择。为了发出某种语言的语音,必须下载并安装对应的语音合成数据包。
请【一定要】在这里下载并安装:
http://go.microsoft.com/fwlink/?LinkID=223569&clcid=0x409如果希望不止是运行,而能够开发语音识别/语音合成应用程序,到以下地址下载 MS Speech Platform SDK 11 并安装:
http://go.microsoft.com/fwlink/?LinkID=223570&clcid=0x409以下是源代码,只需要在VS2012中建立一个窗体应用程序,并创建 textbox1 combobox1 button1 三个控件即可使用以下代码。
请添加对Microsoft.Speech的引用,所需dll文件在SDK安装路径下的Assembly目录中。
-----------------------------------------------------------------
Imports Microsoft.Speech.SynthesisPublic Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If s.State = SynthesizerState.Speaking Then s.SpeakAsyncCancelAll()
Return
End If
Dim iv = s.GetInstalledVoices For Each i As InstalledVoice In iv
If i.VoiceInfo.Name.Contains(ComboBox1.Text) Then s.SelectVoice(i.VoiceInfo.Name) End If
Next
s.SpeakAsync(TextBox1.Text)
End Sub
Dim s As SpeechSynthesizer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
s = New SpeechSynthesizer()
Dim iv = s.GetInstalledVoices For Each i As InstalledVoice In iv
ComboBox1.Items.Add( _ Strings.Right(i.VoiceInfo.Name, i.VoiceInfo.Name.Length + 1 - InStr(i.VoiceInfo.Name, "(")) _ )
Next
ComboBox1.Text = ComboBox1.Items(0) s.SetOutputToDefaultAudioDevice() End Sub
End Class
-------------------------------------------------------------------
或者,直接使用这个VS2012工程:
HelloSpeech.rar
117.29KB
RAR
29次下载
200字以内,仅用于支线交流,主线讨论请采用回复功能。