Examining the Dragon Speech-Recognition System
by Al Williams

Example 1:
If Not IsDDWinRunning() Then ' Dragon not running
  If Not StartDDWin() Then ' Didn't start up either
     MsgBox "Can't start DragonDictate"
  End If
End If


Listing One
VERSION 5.00
Object = "{C9F1DD69-49F9-11D0-B5C5-444553540000}#1.0#0"; "dd32.ocx"
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form MainForm 
   Caption         =   "Voice Dialer"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton ManDial 
      Caption         =   "Number"
      Height          =   495
      Left            =   120
      TabIndex        =   3
      Top             =   1560
      Width           =   975
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   720
      Top             =   2520
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   327680
      DTREnable       =   0   'False
   End
   Begin VB.CommandButton Delete 
      Caption         =   "Remove"
      Height          =   495
      Left            =   120
      TabIndex        =   2
      Top             =   840
      Width           =   975
   End
   Begin VB.CommandButton Add
      Caption         =   "Add"
      Height          =   495
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   975
   End
   Begin VB.ListBox List1 
      Height          =   2790
      Left            =   1320
      Sorted          =   -1  'True
      TabIndex        =   0
      Top             =   120
      Width           =   3135
   End
   Begin DDSpeechLib.DDSpeech DDSpeech1 
      Left            =   120
      Top             =   2640
      _Version        =   65536
      _ExtentX        =   741
      _ExtentY        =   741
      _StockProps     =   0
   End
End
Attribute VB_Name = "MainForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Add_Click()
' Name, number, and generic string
Dim n As String, nm As String, s As String, word As String
AddForm.Show vbModal
If AddForm.Cancelled <> True Then
  n = AddForm.NewName
  nm = AddForm.NewNumber
  s = n & Chr(9) & nm
  List1.AddItem s
  word = s & "[" & n & "]"
  If DDSpeech1.AddWord("PhBook", "TelNum", word, "'") 
                                       = EXP_ERR_WORD_HAS_NO_MODEL Then
    DDSpeech1.TrainWord = word
  End If
Unload AddForm
End If
End Sub

' Dial a number in the format of name (tab) number [xxx]
' The brackets, if present at all, are ignored
Sub Dial(ByVal word As String)
Dim n As Integer
Dim t0 As Date
Dim dn As String, nam As String  ' Dial number, name
n = InStr(word, Chr(9))
dn = Right(word, Len(word) - n)
nam = Left(word, n - 1)
n = InStr(dn, "[")
If n <> 0 Then dn = Left(dn, n - 1)
MSComm1.PortOpen = True
MSComm1.Output = "ATV1E0DT" & dn & Chr(13)
t0 = DateAdd("s", 5, Now)
Do
    DoEvents
Loop Until Now > t0  ' Wait 5 seconds
MSComm1.PortOpen = False
MsgBox dn, vbOKOnly, "Dialed " & nam
End Sub

'Delete Entry
Private Sub Delete_Click()
Dim n As Integer
Dim word As String, nam As String
n = List1.ListIndex
If n <> -1 Then
  If MsgBox("Delete this entry", vbYesNo) = vbNo Then Exit Sub
  word = List1.Text
  nam = Left(word, InStr(word, Chr(9)) - 1)
  word = word & "[" & nam & "]"
' Delete word from dragon dictionary
  If DDSpeech1.DeleteWord("PhBook", "TelNum", word) Then
    List1.RemoveItem n
  Else
    MsgBox "Can't remove name"
  End If
Else
  MsgBox "Please select a name first"
End If
End Sub

' Manual dial a number
Private Sub ManDial_Click()
Dim nr As String
nr = InputBox("Enter or say the number to dial")
If nr <> "" Then Dial ("Manual Dial" & Chr(9) & nr)
End Sub

Private Sub DDSpeech1_SpeechRecognized(word As String, WordValue As String)
Dim SearchWord As String
Dim i As Integer
' Find string in listbox so we can highlight it
SearchWord = Left(word, InStr(word, "[") - 1)
List1.ListIndex = -1
For i = 0 To List1.ListCount - 1
  If SearchWord = List1.List(i) Then
    List1.ListIndex = i
    Exit For
  End If
Next i
Dial word  ' Do it
End Sub

Private Sub Form_Load()
Dim s As String
Dim n As Integer
' Start Dragon if not already started
If Not IsDDWinRunning() Then
  If Not StartDDWin() Then
    MsgBox "Can't start Dragon Dictate", vbExclamation
    End
  End If
End If
DDSpeech1.Attach = True
DDSpeech1.AddVocabulary "PhBook"
DDSpeech1.AddGroup "PhBook", "TelNum"
DDSpeech1.Vocabulary = "PhBook"
DDSpeech1.Group = "TelNum"
' Load phone numbers already in vocabulary
s = DDSpeech1.WordFirst
Do While s <> ""
  n = InStr(s, "[")
  List1.AddItem (Left(s, n - 1))
  s = DDSpeech1.WordNext
Loop
End Sub

' Double click for those who are speechless!
Private Sub List1_DblClick()
Dial List1.Text
End Sub



4


