步骤如下:
1、在网上下载speechsdk51、speechsdk51LangPack这两个文件并安装,这是微软提供的语音开发包。
2、在VS里新建一个项目,引用语音库,如图:
3、在窗体的按钮里这样写:
Private Sub Button
1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim v As New SpeechLib.SpVoice
v.Speak(ChineseNum(CDec(TextBox1.Text)), SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync)
MsgBox(ChineseNum(CDec(TextBox1.Text)))
End Sub
其实说话的只有这一句代码:
v.Speak(ChineseNum(CDec(TextBox1.Text)), SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync)
4、运行如图:
这时一个动听的男音就会给您报出价格了,呵呵。
这位说什么?女音才能用“动听”?
。。。是的,但是想听女音吗?那就掏银子买开发包吧!
附:下面附上我用到的金额转达写函数
Public Function ChineseNum(ByVal Single_to As Decimal) As String
Dim Str_to As String
Dim PartStr() As String = {"", ""}
Dim i As Integer
Dim Full As Boolean = False
Dim Zero As Boolean = False
Dim Delimiters As Char = CChar(".")
Str_to = CStr(Single_to)
PartStr = Str_to.Split(Delimiters)
Str_to = ""
For i = 0 To PartStr(0).Length - 1
Select Case PartStr(0).Chars(i)
Case CChar("0")
If Zero = False Then
Zero = True
End If
Case CChar("1")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "壹")
Case CChar("2")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "贰")
Case CChar("3")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "叁")
Case CChar("4")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "肆")
Case CChar("5")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "伍")
Case CChar("6")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "陆")
Case CChar("7")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "柒")
Case CChar("8")
Str_to = Str_to.Insert(Str_to.Length, "捌")
Zero = False
Case CChar("9")
If Zero = True Then
Str_to = Str_to.Insert(Str_to.Length, "零")
Zero = False
End If
Str_to = Str_to.Insert(Str_to.Length, "玖")
End Select
Select Case -(i - PartStr(0).Length + 1)
Case 0
Str_to = Str_to.Insert(Str_to.Length, "元")
Case 1
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "拾")
End If
Case 2
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "佰")
End If
Case 3
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "仟")
End If
Case 4
Str_to = Str_to.Insert(Str_to.Length, "万")
Zero = False
Case 5
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "拾")
End If
Case 6
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "佰")
End If
Case 7
If Zero = False Then
Str_to = Str_to.Insert(Str_to.Length, "仟")
End If
Case 8
Str_to = Str_to.Insert(Str_to.Length, "亿")
Zero = False
Case 9
Str_to = Str_to.Insert(Str_to.Length, "拾")
End Select
Next
If PartStr.GetUpperBound(0) <> 0 Then
For i = 0 To PartStr(1).Length - 1
Select Case PartStr(1).Chars(i)
Case CChar("0")
Str_to = Str_to.Insert(Str_to.Length, "零")
Case CChar("1")
Str_to = Str_to.Insert(Str_to.Length, "壹")
Case CChar("2")
Str_to = Str_to.Insert(Str_to.Length, "贰")
Case CChar("3")
Str_to = Str_to.Insert(Str_to.Length, "叁")
Case CChar("4")
Str_to = Str_to.Insert(Str_to.Length, "肆")
Case CChar("5")
Str_to = Str_to.Insert(Str_to.Length, "伍")
Case CChar("6")
Str_to = Str_to.Insert(Str_to.Length, "陆")
Case CChar("7")
Str_to = Str_to.Insert(Str_to.Length, "柒")
Case CChar("8")
Str_to = Str_to.Insert(Str_to.Length, "捌")
Case CChar("9")
Str_to = Str_to.Insert(Str_to.Length, "玖")
End Select
If i = 0 Then
Str_to = Str_to.Insert(Str_to.Length, "角")
Else
Str_to = Str_to.Insert(Str_to.Length, "分")
Full = True
End If
Next
End If
If Not Full Then
Str_to = Str_to.Insert(Str_to.Length, "整")
End If
Return Str_to
End Function