| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1283 人关注过本帖
标题:在pb中用语音读金额
只看楼主 加入收藏
freele_china
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:JiNan
等 级:版主
威 望:6
帖 子:352
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:1 
在pb中用语音读金额
在pb中用语音读金额

 
   1、将金额转换成大写金额;
  2、根据大写金额依次朗读出来;
  为此,需要完成以下内容:
  1、分别录制各WAV文件:0,1,2,3,4,5,6,7,8,9,元,角,分,拾,佰,仟,万,亿,整
  2、在工程中声明两个External 函数(Windows的API函数),用于发声;
         Function boolean sndPlaySoundA (string SoundName, uint Flags) Library "WINMM.DLL"
         Function uint waveOutGetNumDevs () Library "WINMM.DLL"
  3、新建一函数用于在程序中调用发声:
         Function PlaySound(string as_filename,integer ai_option) returns integer
  该函数的代码如下:
        uint lui_numdevs
        lui_numdevs = WaveOutGetNumDevs()
        If lui_numdevs > 0 Then
     sndPlaySoundA(as_filename,ai_option)
        return 1
        Else
    return -1
        End If
  4、新建一函数用于将小写金额转换成大写金额:
        Function xx2dx(Decimal ls) returns string
  代码实现如下:
  string dx_sz,dx_dw,str_int,str_dec,dx_str,fu,a,b,b2,c,d,result
  long num_int,num_dec,len_int,i,a_int,pp
  dx_sz = "零壹贰叁肆伍陆柒捌玖"
  dx_dw = "万仟佰拾亿仟佰拾万仟佰拾元"

 /*处理小于零情况*/
  if ls<0 then
     ls = ls*(-1)
     fu = "负"
  else
       fu = ""
  end if
    /*取得整数及整数串*/
  dx_str = string(ls)
  if (ls>0) and (ls<1) then dx_str = "0"+dx_str
  pp = pos(dx_str,".")
  if pp>0 then
    str_int = mid(dx_str,1,pos(dx_str,".")-1)
  else
    str_int = dx_str
  end if
  num_int = long(str_int)
    /*取得小数及小数串*/
  if (ls>0) and (ls<1) then
    num_dec = ls * 100
  else
    num_dec = (ls - num_int) * 100
  end if
  str_dec = string(num_dec)
  len_int = len(str_int)
  dx_str = ""
    /*转换整整部分*/
  for i = 1 to len_int
      /*a为小写数字字符,b为对应的大写字符,c为对应大写单位,d为当前大写字符串的最后一个汉字*/
     a= mid(str_int,i,1)
     a_int = long(a)
     b = mid(dx_sz,(a_int*2)+1,2)
     c = mid(dx_dw,((13 - len_int +i - 1)*2+1),2)
     if dx_str<>"" then
       d=mid(dx_str,len(dx_str)-1,2)
     else
        d= ""
     end if
     if (b="零") and ((d="零") or (b=b2) or (c="元") or (c="万") or (c="亿")) then  b = ""
     if (a="0") and (c<>"元") and (c<>"万") and (c<>"亿") then c=""
     if ((c="元") or (c="万") or (c="亿")) and (d="零") and (a="0") then
        dx_str = mid(dx_str,1,len(dx_str)-2)
        d=mid(dx_str,len(dx_str)-1,2)
        if ((c="元") and (d="万")) or ((c="万") and (d="亿")) then c = ""
     end if
      dx_str = dx_str + b+ c
      b2 = b
  next
    /*处理金额小于1的情况*/
    if len(dx_str) <= 2 then dx_str= ""
    /*转换小数部分*/
    if (num_dec<10) and (ls>0) then
      a_int = long(str_dec)
      b = mid(dx_sz,(a_int*2+1),2)
      if num_dec = 0 then dx_str = dx_str + "整"
      if num_dec > 0 then dx_str = dx_str +"零"+b+"分"
    end if
 
    if num_dec >= 10 then
      a_int = long(mid(str_dec,1,1))
      a = mid(dx_sz,(a_int*2+1),2)
      a_int = long(mid(str_dec,2,1))
      b = mid(dx_sz,(a_int*2+1),2)
      if a<>"零" then a = a+"角"
      if b <> "零" then
    b = b+"分"
      else
   b= ""
      end if
      dx_str = dx_str + a + b
    end if
    if ls= 0 then dx_str = "零元整"
    dx_str = fu+dx_str
 
    result = dx_str
  return result

5、声明一函数,用于最终调用:
        Function MyReadMoney(Decimal AMoney)
       
  代码实现如下:
  integer i,count
         string ls_dxje
  ls_dxje = xx2dx(Amoney)
  count = len(ls_dxje)
  for i= 1 to count step 2
   CHOOSE CASE mid(ls_dxje,i,2)
   CASE "零"
    playsound("0.wav",0)   
   CASE "壹"
    playsound("1.wav",0)   
   CASE "贰"
    playsound("2.wav",0)   
   CASE "叁"
    playsound("3.wav",0)   
   CASE "肆"
    playsound("4.wav",0)   
   CASE "伍"
    playsound("5.wav",0)   
   CASE "陆"
    playsound("6.wav",0)   
   CASE "柒"
    playsound("7.wav",0)   
   CASE "捌"
    playsound("8.wav",0)   
   CASE "玖"
    playsound("9.wav",0)   
   CASE "拾"
    playsound("十.wav",0)   
   CASE "佰"
    playsound("佰.wav",0)   
   CASE "仟"
    playsound("仟.wav",0)   
   CASE "万"
    playsound("万.wav",0)   
   CASE "亿"
    playsound("亿.wav",0)   
   CASE "元"
    playsound("元.wav",0)   
   CASE "角"
    playsound("角.wav",0)   
   CASE "分"
    playsound("分.wav",0)   
   CASE "整"
    playsound("整.wav",0)   
   END CHOOSE
  next
  6、在程序中,可以任意调用此函数。当然,可以适当加入出错处理一类的代码。
  7、备注:如果不能发声,应检查声音文件是否在可执行文件的同一路径,最好是在函数MyReadMoney中,对各wav文件直接加上路径如C:\temp
搜索更多相关主题的帖子: 语音 金额 
2009-07-18 11:02
Bc_Newboy
Rank: 2
等 级:论坛游民
帖 子:76
专家分:99
注 册:2019-4-14
收藏
得分:0 
2021-09-27 11:19
快速回复:在pb中用语音读金额
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017627 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved