电话语音成绩查询系统
摘 要 本文描述用Visual Basic语言来实现查询学生成绩语音系统的开发过程。
关键词 语音卡,数据库查询,系统开发
一、引言
电话语音查询系统已广泛应用于电话银行、话费查询、证券委托、自动缴费(水、电、气等费用)、语音信箱、自动声讯服务、民航、公共考务、铁路等部门的信息查询以及各种公共场所自动回答顾客提问等领域。
电话语音查询系统的工作流程是用户拨通电话语音查询系统的热线电话,并根据电话中的语音提示,通过按电话键来查询电脑中存储的各种信息; 电脑自动对用户的操作进行应答,并以语音形式将信息反馈给用户。 其组成结构如图1所示。
图1 自动语音查询系统
二、组成
电话语音查询系统是现代电信技术与计算机技术高度结合的产物,一般由硬件和软件两部分组成。
1. 硬件
电话语音查询系统的硬件部分主要包括:电脑、电话语音卡、外线(普通市话线路)或内线。
语音卡,具体地讲,是“电脑与电话语音处理卡”(以下简称为“语音卡”),它是一种用于电脑并能够实现语音处理的电脑插件。语音卡的主要功能是:通过计算机与电话网相连,提供录音、放音、收码(DTMF 码、PULSE 码)、自动拨号、 振铃检测与控制摘挂机、信令检测、转接内线、监控录音、传真、数据传输、主叫号侦测等服务功能。
硬件部分的安装过程极为简单。只要将电话语音卡插入电脑的扩展槽中,再将电话线接至电话语音卡提供的电话插座上,即可构成电话语音查询系统的硬件部分。
2. 软件
软件一般由操作系统、电话语音卡底层驱动软件和二次开发接口软件、电话语音查询系统应用软件等三个部分构成。由于目前电话语音卡的国际标准尚未制订,因此不同生产厂家仍需随卡提供支持各种电话语音功能(如录音、放音、接收和发送双音频码等)的底层驱动软件。但是,很多生产厂家还提供了方便用户进行二次开发的各种编程语言接口(主要以 .DLL 文件格式提供)。
电话语音查询系统应用软件一般由电话语音处理和数据库处理两大程序模块组成。
电话语音处理程序模块的主要任务是负责完成(通过调用底层驱动软件)每条线路的摘挂机控制、放音、录音、接收由用户按键产生的双音频信号以及发送双音频信号等功能,并能够检测各种信号音,如占线、忙音等。
数据库处理程序模块是根据语音处理模块所采集的考号在数据库中查询所对应成绩的模块,是语音查询系统最重要的组成部分之一。
三、实现
1.先把语音卡(我们用北京五岳鑫信息技术有限公司生产的8口的TW_8VID型语音卡)插到电脑主板后重新启动计算机并安装该卡底层驱动软件和二次开发接口软件程序(相关库函数动态连接口),以便电话语音处理。
2.通过语音卡自带的录音功能把欢迎信息、用户操作提示信息、出错提示信息、引导信息、特别是把分数等用中文语音的方式描述出来,以便在语音查询系统的适当过程中播放出来,引导用户正确使用查询系统和获得所需要的信息。
3.打开VB创建一个工程,分别添加5个计时器控件(Timer)及数据库连接控件(Ado),主要用于语音处理和数据库查询,为保证语音处理的实时性,故将每个计时器的Timer属性设置为200ms。核心代码如下:
Dim AppDir As String
Dim MaxChannel As Long
Dim Dig As Double
Dim DataFound As Boolean
Dim DataReturn As String
Dim ReturnValueType As Integer
Dim CurChannel As Integer
Dim ChannelHitKey(0 To 7) As Integer
Dim ChannelSentence(0 To 7) As String
Dim ChannelTW_Folder(0 To 7) As String
Dim ChannelPlayFile(0 To 7) As String
Dim ChannelPlayTotal(0 To 7) As Long
Dim ChannelPlayRest(0 To 7) As Long
Dim ChannelRes(0 To 7) As Long
Dim ChannelPlaySentences(0 To 7) As String
Dim ChannelDataFound(0 To 7) As Boolean
Dim ChannelReturnScore(0 To 7) As String
Dim ChannelReturnValueType(0 To 7) As Integer
Dim ChannelWaiteTime(0 To 7) As Integer
Dim Score(0 To 7) As Integer
Dim ChannelRings(0 To 7) As Integer
Dim ChannelCallingID(0 To 7) As String
Dim ChannelCallingDate(0 To 7) As Date
Dim ChannelCallingStartTime(0 To 7) As String
Dim ChannelCallingEndTime(0 To 7) As String
Dim ChannelStep(0 To 7) As Integer
Dim ChannelLanguage(0 To 7) As Integer
Dim ChannelIsBegin(0 To 7) As Boolean
Dim ChannelSig(0 To 7) As Long
Dim ChannelCount(0 To 7) As Long
Dim ChannelSigLen(0 To 7) As Long
Dim ChannelSigUnuse(0 To 7) As Long
Dim BarCodeStr As String
Dim ChannelBarCodEnterCount(0 To 7) As Integer
Private Sub SetVoice()
TV_SetVoicei CN_END, ""
TV_SetVoicei CN_NOTHING, ""
TV_SetVoicei Asc(0), "voice\d0.tw" '设置各数字及各种语音提示的对应语音文件
TV_SetVoicei Asc(1), "voice\d1.tw"
TV_SetVoicei Asc(9), "voice\d9.tw"
TV_SetVoicei Asc(10), "voice\d10.tw"
TV_SetVoicei Asc(11), "voice\d100.tw"
TV_SetVoicei Asc(12), "voice\fen.tw" '单字“分”的ASCII码
End Sub
Private Sub Form_Load()
Dim Channels As Integer
Channels = TV_Installed()
If Channels = 0 Then
MsgBox "Tw8vid 驱动程序没有安装!"
TV_Disable
End
End If
TV_Initialize '初始化语音卡
Call SetVoice
End Sub
Private Sub Tmr_3_0_Timer()
' 功能: 第三号通道的主控制程序模块
Dim Channel As Integer
Channel = 3
If Channels(Channel).CStatus = WS_HANGUP Then
ChannelRings(Channel) = TV_RingDetect(Channel)
If ChannelRings(Channel) > 2 Then
TV_OffHookCtrl Channel
Call InitializeChannal(Channel)
ChannelStep(Channel) = 1
Channels(Channel).CStatus = WS_OFFHOOK
End If
'End If
If Channels(Channel).CStatus = WS_OFFHOOK Then `处于摘机状态
Select Case ChannelStep(Channel)
Case 1: `用户刚刚登陆系统播放欢迎词
ChannelPlayFile(Channel) = App.Path + "\voice\" + "welcome.tw" `欢迎词
ChannelWaiteTime(Channel) = 25
TV_StartTimer Channel, ChannelWaiteTime(Channel)
Case 2: `提醒用户输入考号
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_2.tw" `请输入考号
ChannelWaiteTime(Channel) = 50
TV_StartTimer Channel, ChannelWaiteTime(Channel)
Case 3: `提醒用户稍等以便系统进入下一个阶段
ChannelPlayFile(Channel) = App.Path + "\voice\" +"\CHN_12.tw" `请稍等
ChannelWaiteTime(Channel) = 50
TV_StartTimer Channel, ChannelWaiteTime(Channel)
ChannelStep(Channel) = 2 `开始输入考号
Case 4:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_3.tw" `您所输入的考号为
ChannelWaiteTime(Channel) = 35
TV_StartTimer Channel, ChannelWaiteTime(Channel)
ChannelStep(Channel) = 5 `开始放音"所输入的考号为"
Case 6:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_4.tw"
确认请按1 ,重新输入请按2,退出本系统请按3
ChannelWaiteTime(Channel) = 15
TV_StartTimer Channel, ChannelWaiteTime(Channel)
ChannelStep(Channel) = 7 `开始放音"确认请按1。。。。"
Case 8:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_11.tw" `请稍等
TmrSearch_3_4.Enabled = True
ChannelStep(Channel) = 8 `开始放音所输入的考号
Case 9:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_5.tw" `'谢谢使用
Case 10:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_10.tw" ` 你的成绩为:。。。。
ChannelWaiteTime(Channel) = 15
TV_StartTimer Channel, ChannelWaiteTime(Channel)
ChannelStep(Channel) = 7
Case 11:
ChannelPlayFile(Channel) = App.Path + "\voice\" + "\Chn_11.tw" `你的成绩尚未录入
End Select
If TV_StartPlayFile(Channel, ChannelPlayFile(Channel), 0, LONG_MAX) = -1 Then
MsgBox "放音失败!", MB_ICONSTOP, "监听外线"
TV_HangUpCtrl Channel
ChannelIsBegin(Channel) = True
Else `正在开始放音"
Channels(Channel).CStatus = WS_PLAYING
TV_FlushDTMF (Channel)
Select Case ChannelStep(Channel)
Case 1
TmrChoose_3_1.Enabled = True
Case 2
TmrInputExamCode_3.Enabled = True `启动考号输入操作监测模块
ChannelExamCode(Channel) = ""
ChannelSentence(Channel) = ""
Case 7
TmrConfirm_3_3.Enabled = True `启动确认按键
End Select
End If
End If
If Channels(Channel).CStatus = WS_PLAYING Then
Select Case TV_PlayFileRest(Channel)
Case -1
MsgBox "放音失败!", MB_ICONSTOP, "监听外线"
TV_HangUpCtrl Channel
Channels(Channel).CStatus = WS_HANGUP
Case 0
Channels(Channel).CStatus = WS_WAITING
If ChannelStep(Channel) = 5 Then
TV_PlaySentence Channel, ChannelSentence(Channel)
Channels(Channel).CStatus = WS_PLAYINGSENTENCE
ChannelRes(Channel) = 0
TmrReadData_3_2.Enabled = True
`启动读出用户所输入考号模块
End If
If ChannelStep(Channel) = 7 Then
TV_PlaySentence Channel, ChannelSentence(Channel)
Channels(Channel).CStatus = WS_PLAYINGSENTENCE
ChannelRes(Channel) = 0
ChannelStep(Channel) = 12 `设置为查询完毕
End If
If ChannelStep(Channel) = 8 Then TmrSearch_3_4.Enabled = True
If (ChannelStep(Channel) >= 9) And (ChannelStep(Channel) <= 12) Then
TV_HangUpCtrl Channel
Channels(Channel).CStatus = WS_HANGUP
ChannelIsBegin(Channel) = False
End If
End Select
End If
If (ChannelStep(Channel) = 9) And (Channels(Channel).CStatus = WS_ENDSEARCHING) Then
If ChannelDataFound(Channel) Then
Score(Channel)= Val(Trim(ChannelReturnScore(Channel)))
ChannelSentence(Channel) =""
Select Case Trim(ChannelReturnScore(Channel))
Case "100"
ChannelSentence(Channel) = String(1, Chr(11) ) `“一百分”语音
Case Else
If (Score(Channel))<=10 then
ChannelSentence(Channel) =String(1, Chr(Score(Channel))) `“几分”语音
Else
ChannelSentence(Channel) =String(1, Chr(Score(Channel)\10))+ String(1, Chr(10))+ String(1, Chr(Score(Channel) Mod 10)) `“几十几分”语音
End If
End Select
ChannelStep(Channel) =10
Else
ChannelStep(Channel) =11
End If
TV_StopPlayFile (Channel) `停止“请稍等”语音
Channels(Channel).CStatus = WS_OFFHOOK
End If
End Sub
Private Sub TmrChoose_3_1_Timer()
`功能: 第三号通道开始工作时选择服务类别
Dim Channel As Integer
Channel = 3
If (ChannelStep(Channel) = 1) And (Channels(Channel).CStatus = WS_PLAYING Or Channels(Channel).CStatus = WS_WAITING Or Channels(Channel).CStatus = WS_DTMF) Then
ChannelHitKey(Channel) = TV_GetDTMFChar(Channel)
If ChannelHitKey(Channel) <> -1 Then
TV_StopPlayFile (Channel)
Channels(Channel).CStatus = WS_DTMF
Select Case ChannelHitKey(Channel)
Case 49:
TV_StopPlayFile (Channel)
Channels(Channel).CStatus = WS_OFFHOOK
ChannelStep(Channel) = 2 `服务选择为开始输入卡号
TmrChoose_3_1.Enabled = False
Case 50:
TV_StopPlayFile (Channel)
Channels(Channel).CStatus = WS_OFFHOOK
ChannelStep(Channel) = 2 `退出本系统
TmrChoose_3_1.Enabled = False
End Select
ElseIf (TV_TimerElapsed(Channel) = -1) Then
Channels(Channel).CStatus = WS_OFFHOOK
ChannelStep(Channel) = 9 `超时直接退出本系统
TmrChoose_3_1.Enabled = False
End If
End If
End Sub
Private Sub TmrReadData_3_2_Timer()
`功能: 第三号通道 ,给用户读出所输入考号数据
Dim Channel As Integer
Channel = 3
If (ChannelStep(Channel) = 5) And (Channels(Channel).CStatus = WS_PLAYINGSENTENCE) Then
ChannelRes(Channel) = TV_PlaySentenceRest(Channel)
Select Case ChannelRes(Channel)
Case 0
ChannelStep(Channel) = 6
Channels(Channel).CStatus = WS_OFFHOOK
TmrReadData_3_2.Enabled = False
Case -2
'MsgBox "未定义的文件名", MB_ICONSTOP, "读数字"
End Select
End If
End Sub
Private Sub TmrInputExamCode_3_Timer()
`功能: 第三号通道 , 输入考号数据
Dim Channel As Integer
Channel = 3
If (ChannelStep(Channel) = 2) And (Channels(Channel).CStatus = WS_PLAYING Or Channels(Channel).CStatus = WS_WAITING Or Channels(Channel).CStatus = WS_DTMF) Then
ChannelHitKey(Channel) = TV_GetDTMFChar(Channel)
If ChannelHitKey(Channel) <> -1 Then
TV_StopPlayFile (Channel)
Channels(Channel).CStatus = WS_DTMF
Select Case ChannelHitKey(Channel)
Case 48 To 57:
ChannelExamCode(Channel) = Trim(ChannelExamCode(Channel)) + String(1, Chr(ChannelHitKey(Channel)))
ChannelSentence(Channel) = Trim(ChannelSentence(Channel)) + String(1, Chr(ChannelHitKey(Channel) )
Case 35:
If Len(ChannelExamCode(Channel)) <> 10 Then
ChannelExamCode(Channel) = ChannelSentence(Channel) + "输入有误"
ChannelStep(Channel) = 3 `输入数据有误
ChannelExamCode(Channel) = ""
ChannelSentence(Channel) = ""
Else
ChannelStep(Channel) = 4 `输入数据正确、确认、重新输入
End If
Channels(Channel).CStatus = WS_OFFHOOK
TmrInputExamCode_3.Enabled = False
End Select
ElseIf (TV_TimerElapsed(Channel) = -1) Then
Channels(Channel).CStatus = WS_OFFHOOK
ChannelStep(Channel) = 9 `退出本系统
End If
End If
End Sub
Private Sub TmrSearch_3_4_Timer()
`功能: 第三号通道 ,按考号进行查询操作
'Dim Examcode_str As String
Dim Channel As Integer
Channel = 3
TmrSearch_3_4.Enabled = False
If (ChannelStep(Channel) = 8) Then
Adodc1.RecordSource = "SELECT EXAMVAL FROM STUDRECORD WHERE EXAMCODE=" + "'" + ChannelExamCode(Channel) + "'"
Adodc1.Refresh
If Not Adodc1.Recordset.EOF Then `库中存在此考生信息
ChannelDataFound(Channel) = True
ChannelReturnScore (Channel) = Adodc1.Recordset.Fields("EXAMVAL").Value & ""
Else
ChannelDataFound(Channel) = False `库中不存在此考生信息
End If
Channels(Channel).CStatus = WS_ENDSEARCHING
ChannelStep(Channel) = 9
End If
End Sub
四、测试
当外线电话打入时,计算机自动检测到振铃信号,并开始播放提示音,同时开始接收用户的电话按键信息。用户通过电话按键输入考号,计算机根据接收的信息从后台数据库中取得查询结果数据,并将相应分数数据进行语音合成,再通过语音卡的相应外线电话通道播放查询结果。
五、结语
在通讯技术飞速发展且普及的今天,利用电话这一最为百姓常用的通讯工具并开发相应的各类信息查询软件,实现无论在何时何地均可查询本(用)户所需信息,确实是一件方便用户的好事,值得供各类信息服务提供者的推广应用。本文提供了实现语音成绩查询系统的整个源代码,相信读者利用这些源程序可以开发出适合自己需求的语音查询系统。
参考文献
1.MICHAEL B.计算机电话系统-CTI与呼叫中心[M].姜晓铭译.北京电子工业出版社,2002
2.肖小红王芙蓉.基于cti开放平台的呼叫中心的设计和实现[J].微型电脑应用, 2001
3.杨永川陆山.公安信息系统分析与设计[M].警官教育出版社,1997
|