Solved

Add voice greeting to my Access app.

Posted on 2004-10-09
23
413 Views
Last Modified: 2012-06-27
I want to cbe able to add a audio voice greeting to my app to greet the user. There will be different users so I need it to be generic and address the person by username.
0
Comment
Question by:Idarac
  • 13
  • 4
  • 3
  • +1
23 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
0
 
LVL 2

Assisted Solution

by:bbaldwin
bbaldwin earned 100 total points
Comment Utility
This solution requires that you put the .wav files into a folder for playback. The .wav files must be named the user's windows logon name. For example: bgates would have a bgates.wav file that is his greeting.

Just copy the code into a new module and call the Greet() function when you open the database.

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
   (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
   Declare Function GetWindowsDirectoryA Lib "Kernel32" _
   (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Sub Greet()
Dim n As Integer, strDir As String, strUser As String

strDir = CurrentDBDir() 'if the greeting .wav files are in the DB dir
'strDir = "c:\Greetings" 'use this as an optional location

strUser = CurrentUserName()

n = sndPlaySound(strDir & strUser & ".wav", 0)

End Sub

Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
    strDBPath = CurrentDb.Name
    strDBFile = Dir(strDBPath)
    CurrentDBDir = Left(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function

Public Function CurrentUserName()
    ' Display the name of the user currently logged on.
    Dim UserName As String  ' receives name of the user
    Dim slength As Long  ' length of the string
    Dim RetVal As Long  ' return value
   
    ' Create room in the buffer to receive the returned string.
    UserName = Space(255)  ' room for 255 characters
    slength = 255  ' initialize the size of the string
    ' Get the user's name and display it.
    RetVal = GetUserName(UserName, slength)  ' slength is now the length of the returned string
    UserName = Left(UserName, slength - 1)  ' extract the returned info from the buffer
    ' (We subtracted one because we don't want the null character in the trimmed string.)
    CurrentUserName = UserName
End Function
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
A few yesrs back there was (and still exists) a
VoiceText 1.0 type library that made it very easy ...

    'get instance of Voice object and register it
    Set oVoice = New VTxtAuto.VTxtAuto
    oVoice.Register App.Title, App.EXEName
    oVoice.Callback = "Speak2Me.VTxtCallback"
   
    'greet user
    oVoice.Speak txtTextToSpeak, vtxtst_READING


in this example I had a text box txtTextToSpeak that I had populated with the user's name based on a lookup I did on their network logon.


You could also use the Office Agent (as opposed to the Assistant) to play with Text to speech.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrmicrosoftagentactivexcontrolvsofficeassistant.asp

Steve
0
 
LVL 39

Accepted Solution

by:
stevbe earned 400 total points
Comment Utility
ok ... just was playing some more ... I think that the speech api should already be on most PCs ...
I made a reference to the Microsoft Speeh Library


Public Function SayThis(MyText As String)

Dim myVoice As SpeechLib.SpVoice

Set myVoice = New SpeechLib.SpVoice
myVoice.Speak MyText

End Function

Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
If you don't already have the speech api it is a free download. but I think this is what Office uses anyway so it really should be on the PC already. Because it is a free download probably means you can include it in a delivery package to clients who do not (or might not) have it but I have not read a EULA on it so please be careful. Beyond the fun we could have with this I can see how this would be very valuable in making your application accessible to people with a vision impairment.

Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
How are you getting the username? do you need help with that?

Steve
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
Steve, thanks for that - I have no idea what I will use it for but there must be something I can build into my apps that use it...heh heh :-)
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
beyond the sily, I think you could actually build command recognition ... "Tell Me Employee ID" and have that value read back ... you could do it at the record level ... "Read"

strSpeek = "Employee ID is " & Me.txtEmpID
strSpeek = strSpeak & ", First Name is " & Me.txtFirstName

Call myVoice.Speak strSpeak

Steve
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
I was thinking more along the lines of voice prompts for "dangerous" actions such as customer account deletions. Too many people simply hit "next","yes" or "ok" without actually reading what the prompt says (although I now require users to reconfirm their passwords to carry out this sort of thing).
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
just took a quick look at he library ... too much to grasp in 2 minutes but there is quite a bit to work with, I am sure you could get it to not only recognixze commands to make the app do something but also get it to convert speech to text and enter that in fields, and yes you can read it backm before entry :-)

Sounds like either a lot of work for 1 person or perhaps an open source project :-)

Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
I like new stuff too much ... sometimes I distract myself :-)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:stevbe
Comment Utility
"dangerous" actions such as customer account deletions.

I have tried to convince management that these type of functions shpould only be processed as part of a "year end" or "period end" process so the app does not let you orphan or delete records until you either archive or purge. I have no success to date but I mention it every time they say ... can I get that record back !!!! Interestingly enough that situation usually only happens with IT apps and none of the other divisions :-)

Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
lol ... don't tell them just implement the voice :-)


"Initializing shout down, I mean shut down sequence"

"Does the boss really need this report?"

add a table to store random adjectives to change things for each message?

"This query is a doozy, it will take me a few minutes"
                      ^whopper, doozy, dilly, killer^


Steve
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
> "Does the boss really need this report?"

This one I like <G>

Or if they click "No" to the record deletion prompt:
"All customer records deleted. <pause> Just kidding...."
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
lol ... "Now formatting hard drive ... please wait"

but seriously ... If we extend the concept of a centralized error handler and make it a centralized message handler then you would only need to write the code in that function rather than in all of the indiviual sub/functions.

not counting the voice part, I use to write all of my code with a message handler but have since broke things up into messaging and errors ... perhaps time to re-think .... nope ...the boss will not buy into the voice thing anyway.

I used Err.Raise with custom error numbers everywhere and then looked up the message in a table to get the actual message I wanted to display. I think you could pass an argument (similar to messagebox buttons) that you can use to determine if it is a simple data validation (text instead of date, no in list, etc.) or a real error that needs to be logged.

Steve
0
 
LVL 2

Expert Comment

by:bbaldwin
Comment Utility
Where is Idarac on this?? We have not heard from him since comment #1!
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
most of the time we never hear back from the person who originally posted the question so I wouldn't hold my breath if I was you :-)

Steve
0
 
LVL 1

Author Comment

by:Idarac
Comment Utility
You don't have to hold your breath, I am here. If fact if you check my questions history I have engaged and awared on every question. The only deletion I have had was because of lack of expert participation.

I am keenly interested in the VoiceText library. I take it that it will take a peice of text and the sound will be based on the text. Thats exactly what I am looking for. Does anyone know where I can get it? Or how I can check if it is on my system?


Great to see so much feedback. Thanx everyone for participating.
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
I apologize if I sounded rude or sarcastic ... that was not my intent

my original post referred to an old library but there is a new one that I think is part of the OS now and is much easier to use. You will need to set a reference to the Microsoft Speeh Library and then use this code ... If Microsoft Speach Library is not listed in your rferences dialog box then you can get it from MS., sorry I don't have a link to a download as it was already on my PC and I did not do a specific download for it.


Public Function SayThis(MyText As String)

Dim myVoice As SpeechLib.SpVoice

Set myVoice = New SpeechLib.SpVoice
myVoice.Speak MyText

End Function

Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
I would put the speach functions in a seperate module but you could do it directly in your startup form's Open event ...

Private Sub Form_Open(Cancel As Integer)

Dim myVoice As SpeechLib.SpVoice

Set myVoice = New SpeechLib.SpVoice
myVoice.Speak GetUserName   'GetUsername is a function to obtain the user's full name
Set myVoice = Nothing

End Sub
0
 
LVL 2

Expert Comment

by:bbaldwin
Comment Utility
Ahh, I had no idea that you were looking for text to speech. I thought you were going to record a greeting as a .wav file.
0
 
LVL 1

Author Comment

by:Idarac
Comment Utility
The text to speech works excellent!!!
0
 
LVL 1

Author Comment

by:Idarac
Comment Utility
I am giving baldwin a 100 points for effort because I was not specific in my request.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now