我想用VB编一个语音报数程序,请问要如何做啊,要求如下
能普通话报出任意数,比如 输入 87654.21
就能报出 你的费用为8万7千6百5十4元2角1分
望版主快快帮忙,让我有信心再次来这里
程序写好了,可惜我没有声音文件,没测试,你找到声音文件(自已录也行),改名为 一.wav 二.wav ....就可以了
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Function rmb(num As Double) As String num = FormatNumber(num, 2) Dim numList As String Dim rmbList As String Dim numLen As Integer Dim numChar As Integer Dim numstr As String Dim n As Integer Dim n1 As String, n2 As String Dim hz As String
numList = "零壹贰叁肆伍陆柒捌玖" rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万"
If num > 9999999999999.99 Then rmb = "超出范围的人民币值" Exit Function End If
numstr = CStr(num * 100) numLen = Len(numstr) n = 1 Do While n <= numLen numChar = CInt(Mid(numstr, n, 1)) n1 = Mid(numList, numChar + 1, 1) n2 = Mid(rmbList, numLen - n + 1, 1) If Not n1 = "零" Then hz = hz + CStr(n1) + CStr(n2) Else If n2 = "亿" Or n2 = "万" Or n2 = "元" Or n1 = "零" Then Do While Right(hz, 1) = "零" hz = Left(hz, Len(hz) - 1) Loop End If If (n2 = "亿" Or (n2 = "万" And Right(hz, 1) <> "亿") Or n2 = "元") Then hz = hz + CStr(n2) Else If Left(Right(hz, 2), 1) = "零" Or Right(hz, 1) <> "亿" Then hz = hz + n1 End If End If End If n = n + 1 Loop Do While Right(hz, 1) = "零" hz = Left(hz, Len(hz) - 1) Loop If Right(hz, 1) = "元" Then hz = hz + "整" End If rmb = hz End Function
Private Sub SpeakOut(Money As String) Dim Path As String Dim i As Integer Path = IIf(Len(App.Path) = 3, App.Path, App.Path & "\") For i = 1 To Len(Money) sndPlaySound (Path & Mid(Money, i, 1) & ".wav") Next End Sub
Private Sub Command1_Click() SpeakOut (rmb(CDbl(Text1.Text))) End Sub
客气,客气