程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB6 >> VB實現的電話語音成績查詢系統

VB實現的電話語音成績查詢系統

編輯:VB6

一、引言

電話語音查詢系統已廣泛應用於電話銀行、話費查詢、證券 委托、自動繳費(水、電、氣等費用)、語音信箱、自動聲訊服務、民航、公共 考務、鐵路等部門的信息查詢以及各種公共場所自動回答顧客提問等領域。

電話語音查詢系統的工作流程是用戶撥通電話語音查詢系統的熱線電話, 並根據電話中的語音提示,通過按電話鍵來查詢電腦中存儲的各種信息; 電腦自 動對用戶的操作進行應答,並以語音形式將信息反饋給用戶。其組成結構如圖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), "voiced0.tw"     '設置各數字及各種語音提示

的對應語音文件
TV_SetVoicei Asc(1), "voiced1.tw"
 
TV_SetVoicei Asc(9), "voiced9.tw"
TV_SetVoicei Asc(10), "voiced10.tw"
TV_SetVoicei Asc(11), "voiced100.tw"
TV_SetVoicei Asc(12), "voicefen.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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved